Skip to content

Commit

Permalink
clean up geo file; fix build from scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfitz committed Oct 12, 2019
1 parent 6a89706 commit 0bfde89
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 77 deletions.
132 changes: 57 additions & 75 deletions msg/COS_Geo.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,34 @@

# let us try to make a slightly more interesting world

(define make-table
(lambda (lst)
(reduce (? x | ? h |
assign name (car | x) |
assign obj (cdr | x) |
hash-add (h) (name) (obj))
(append (hash-null) (lst)))));
(define make-table | ? lst |
reduce
(? x | ? h |
assign name (car $x) |
assign obj (cdr $x) |
hash-add $h $name $obj)
(append $hash-null $lst));

# note, the quoted strings below are just represented as a big number,
# nothing special
(define geo-map
(make-table
(map
(? name (cons (name) (room new (name))))
(vector "boston" "dublin" "paris" "genoa"))));

(define my-links
(map
(? entry (assign src (car | entry) |
assign dest (cdr | entry) |
door new (geo-map | src) (geo-map | dest)))
(define geo-map | make-table | map
(? name | cons $name | room new $name)
(vector "boston" "dublin" "paris" "genoa"));

(define my-links | map
(? entry |
assign src (car $entry) |
assign dest (cdr $entry) |
door new (geo-map $src) (geo-map $dest))
(vector
(cons "boston" "dublin")
(cons "dublin" "paris")
(cons "boston" "paris")
(cons "paris" "genoa"))));
(cons "paris" "genoa")));

(define myrobo (robo new));
(define myrobo | robo new);

(myrobo set-room (geo-map "dublin"));
(myrobo set-room | geo-map "dublin");

(demo | myrobo get-room name);

Expand Down Expand Up @@ -64,60 +62,44 @@
# all characters should update together

(class world (the-places the-links)
(field things (container new))
(field names (cell new (hash-null)))
(field places (cell new 0))
(field links (cell new 0))
(method new
(begin
(places set
(make-table
(map
(? name (cons (name) (room new (name))))
(the-places))))
(links set
(map
(? entry (assign src (car | entry) |
assign dest (cdr | entry) |
door new
(places get | src)
(places get | dest)))
(the-links)))))
(method add (lambda (place name val)
(begin
(val set-room (places get | place))
(val set-name | name)
(names set (hash-add (names get)
(name)
(val)))
(things add (val)))))
(method find (lambda (n) (names get (n) get-room name)))
(method reachable (lambda (place)
(let ((exits
(select-match (lambda (x)
(instanceof door (x)))
(places get (place) inventory))))
(map (? door (door access-from
(places get | place)
name))
(exits)))))
(method update (begin
(map (? x (x update))
(things inventory))
(true))));

(define geo-world
(world new
(vector "boston" "dublin" "paris" "genoa")
(vector
(cons "boston" "dublin")
(cons "dublin" "paris")
(cons "boston" "paris")
(cons "paris" "genoa"))));

(geo-world add "dublin" "robo1" (robo new));

(geo-world add "genoa" "robo2" (robo new));
(field things | container new)
(field names | cell new $hash-null)
(field places | cell new 0)
(field links | cell new 0)
(method new | begin
(places set | make-table | map
(? name | cons $name | room new $name)
$the-places)
(links set | map
(? entry |
assign src (car $entry) |
assign dest (cdr $entry) |
door new (places get $src) (places get $dest))
$the-links))
(method add | lambda (place name val) | begin
(val set-room | places get $place)
(val set-name $name)
(names set | hash-add (names get) $name $val)
(things add $val))
(method find | ? n | names get $n get-room name)
(method reachable | ? place |
assign exits (select-match (instanceof door) | places get $place inventory) |
map (? door | door access-from (places get $place) name) $exits)
(method update | begin
(map (? x | x update) | things inventory)
$true));

(define geo-world | world new
(vector "boston" "dublin" "paris" "genoa")
(vector
(cons "boston" "dublin")
(cons "dublin" "paris")
(cons "boston" "paris")
(cons "paris" "genoa")));

(geo-world add "dublin" "robo1" | robo new);

(geo-world add "genoa" "robo2" | robo new);

(demo | geo-world find "robo1");
(demo | geo-world find "robo2");
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ set(ACTIVE_DEPENDS)
set(ACTIVE_DEPENDS_SHORT "")
set(EXTRA_DEPEND_pl ${MSG}/cosmic.pm)
set(EXTRA_DEPEND_js ${MSG}/cosmic.js)
set(EXTRA_DEPEND_gate ${CMAKE_SOURCE_DIR}/src/filter/drawgate-ppm.pl ${CMAKE_SOURCE_DIR}/src/filter/drawgate-txt.pl ${UnlessDriverLoc})
set(EXTRA_DEPEND_java ${FritzifierLoc})
set(EXTRA_DEPEND_gate ${CMAKE_SOURCE_DIR}/src/filter/drawgate-ppm.pl ${CMAKE_SOURCE_DIR}/src/filter/drawgate-txt.pl UnlessDriver ${UnlessDriverLoc})
set(EXTRA_DEPEND_java Fritzifier ${FritzifierLoc})
foreach(depend ${COSMIC_DEPENDS})
foreach(ext md pl scm gate java js)
if(EXISTS ${MSG}/${depend}.${ext})
Expand Down

0 comments on commit 0bfde89

Please sign in to comment.