Skip to content

Commit

Permalink
21820: Fixes outdated examples (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
howsoRes authored Oct 10, 2024
1 parent a5425fe commit 42ebdba
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 115 deletions.
48 changes: 24 additions & 24 deletions AMALGAM-BEGINNER-GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ if you want to change their values, you need to use the **(assign** opcode:
For example, after you create a variable called **my\_list** that has a
list of letters:
(declare (assoc my_list (list "a" "b" "c")))
(declare (assoc my_list ["a" "b" "c"] ))
if you want to now edit **my\_list** and append the letter "d" to it,
if you simply do this:
Expand All @@ -143,7 +143,7 @@ if you simply do this:
nothing will happen because even though the code is evaluated, we didn't
'do' anything to the evaluated outcome, we didn't store it into anything! To update what value **my\_list** stores we have to do this:
(assign (assoc my_list (append my_list "d")))
(assign (assoc my_list (append my_list "d") ))
To make this easier, Amalgam has the **(accum** opcode that can be used as such:
Expand All @@ -156,8 +156,8 @@ More examples of basic list operations:
;declare a couple of lists of letters
(declare (assoc
kitty (list "A" "B" "C" "D" "E")
bunny (list "x" "y" "z")
kitty ["A" "B" "C" "D" "E"]
bunny ["x" "y" "z"]
))
;different types of list operations
Expand All @@ -167,26 +167,26 @@ More examples of basic list operations:
last_in_kitty (last kitty) ; result is "E"
;(trunc removes items from the end of a list
truncate_1_item_in_kitty (trunc kitty) ; result is (list "A" "B" "C" "D")
truncate_1_item_in_kitty (trunc kitty) ; result is ["A" "B" "C" "D"]
truncate_all_items_in_kitty_leaving_2 (trunc kitty 2) ; result (list "A" "B" )
truncate_all_items_in_kitty_leaving_2 (trunc kitty 2) ; result ["A" "B"]
truncate_2_items_in_kitty (trunc kitty -2) ; result (list "A" "B" "C" )
truncate_2_items_in_kitty (trunc kitty -2) ; result ["A" "B" "C"]
;(tail removes items from the front of a list
remove_1_item_from_front_of_kitty (tail kitty) ; result is (list "B" "C" "D" "E")
remove_1_item_from_front_of_kitty (tail kitty) ; result is ["B" "C" "D" "E"]
remove_all_from_front_of_kitty_leaving_2 (tail kitty 2) ; result is (list "D" "E")
remove_all_from_front_of_kitty_leaving_2 (tail kitty 2) ; result is ["D" "E"]
remove_2_items_from_front_of_kitty (tail kitty -2) ; result is (list "C" "D" "E")
remove_2_items_from_front_of_kitty (tail kitty -2) ; result is ["C" "D" "E"]
;(append is straight forward
kitty_and_bunny (append kitty bunny) ;result is (list "A" "B" "C" "D" "E" "x" "y" "z")
kitty_and_bunny (append kitty bunny) ;result is ["A" "B" "C" "D" "E" "x" "y" "z"]
size_of_kitty (size kitty) ;result is 5
reverse_of_kitty (reverse kitty) ;result is (list "E" "D" "C" "B" "A")
reverse_of_kitty (reverse kitty) ;result is ["E" "D" "C" "B" "A"]
))
)
Expand Down Expand Up @@ -245,8 +245,8 @@ Use `(assign` to set previously declared variables.
>
> ;Amalgam
> (declare (assoc x 5)) ;declare and set variable x to 5
> (declare (assoc x (list "a" "b" "c"))) ;does nothing because x has already been declared
> (assign (assoc x (list "a" "b" "c"))) ;sets variable x to a list of letters instead
> (declare (assoc x (list "a" "b" "c") )) ;does nothing because x has already been declared
> (assign (assoc x (list "a" "b" "c") )) ;sets variable x to a list of letters instead
More examples with descriptions:
Expand All @@ -255,22 +255,22 @@ More examples with descriptions:
;a (declare (assoc will create an assoc of key -> value pairs where the values can be code itself.
;note: the declaration can be treated as though it's done in parallel, so you CANNOT use values in the same declare to
; calculate subsequent values like so:
(declare (assoc x 3 y 2 foo (* x y)))
(declare (assoc x 3 y 2 foo (* x y) ))
(print foo "\n") ;outputs 0 because foo has already been evaluated, and when it was, x and y were nulls
)
(seq
;if you want to use declared values to make new values, you have to chain the declare statements like so:
(declare (assoc x 3 y 2))
(declare (assoc foo (* x y))) ;the multiplication is evaluated right here so the result is stored in foo
(declare (assoc foo (* x y) )) ;the multiplication is evaluated right here so the result is stored in foo
(print foo) ;thus we get the expected result of 6 here
)
;if we want foo to be a function, we need to make sure the code isn't evaluated right away, to do that we wrap it in a 'lambda'
(seq
(declare (assoc x 3 y 2))
(declare (assoc foo (lambda (* x y)))) ;the multiplication is stored as the code itself, WITHOUT being evaluated
(declare (assoc foo (lambda (* x y)) )) ;the multiplication is stored as the code itself, WITHOUT being evaluated
(print "foo: " foo "\n") ;thus this returns the unevaluated code for the multiplication that's stored into foo
Expand Down Expand Up @@ -369,7 +369,7 @@ coding standards, but can be unlabeled variables as well.
> ;outputs: 8
>
> ;unlabeled function definition:
> (declare (assoc mul (lambda (* x y))))
> (declare (assoc mul (lambda (* x y)) ))
Notes:
Expand Down Expand Up @@ -607,8 +607,8 @@ usage: *(get <code><index>)*
Getting an individual value from a list or an assoc is basic - you just specify the index of the item you want:
(seq
(declare (assoc
numbers (list 10 20 30 40 50)
numbers_map (assoc "a" 10 "b" 20 "c" 30)
numbers [10 20 30 40 50]
numbers_map { "a" 10 "b" 20 "c" 30 }
))
(declare (assoc
Expand All @@ -628,8 +628,8 @@ using a list as the parameter:
(seq
(declare (assoc
numbers (list 10 20 (list "a" "b") 40 50)
numbers_map (assoc "a" 10 "b" 20 "c" (assoc "A" 1 "B" (list 2 4 8)))
numbers (list 10 20 ["a" "b"] 40 50)
numbers_map (assoc "a" 10 "b" 20 "c" {"A" 1 "B" [2 4 8]} )
))
(declare (assoc
Expand All @@ -651,8 +651,8 @@ usage: *(set <code> <index> <new\_code>)*
(seq
(declare (assoc
numbers (list 10 20 30 40 50)
numbers_map (assoc "a" 10 "b" 20 "c" 30)
numbers [10 20 30 40 50]
numbers_map {"a" 10 "b" 20 "c" 30}
))
(declare (assoc
Expand Down
42 changes: 21 additions & 21 deletions examples/api_discovery/number_services.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@

;concatenated version
#version (get (load "version.json") "version")

;major version
#major_version 0

;minor version
#minor_version 1

;patch version
#patch_version 0

;returns a structure containing all of the API details for this module
#get_api
(seq
(assoc
"description"
(get_entity_comments)

"labels"
(map (lambda
(assoc
"description"
(target_value 1)
(current_value 1)
"parameters"
(get_entity_comments (null) (target_index 1) (true))
(get_entity_comments (null) (current_index 1) (true))
)
)
(get_entity_comments (null) (null) (true))
)
)
)


;returns true if number is even, false if it is not
;works for infinity, -infinity
;does not yet support negative numbers -- if a negative number is passed in,
Expand All @@ -49,42 +49,42 @@
; number to be passed in. if none is passed in, defaults to 0
number 0
)

(if
(= number .infinity)
(true)

(= number -.infinity)
(true)

(= number 42)
(assoc "a" (list (null) 3 (null) (list) (assoc "x" 12) .infinity) )

(= number (null))
(list (true) (false))

(< number 0)
"Negative numbers are not yet supported."

(!= (get_type_string number) "number")
"That's not a number."

(if (mod number 2) (false) (true))
)
)

;given the list of numbers, returns an associative array with each key
; being the number and the value being the result of is_even
#are_even
(declare (assoc
;list of numbers
numbers (list)
)
(zip numbers (map (lambda (call is_even (assoc number (target_value 1)))) numbers) )

(zip numbers (map (lambda (call is_even (assoc number (current_value 1)))) numbers) )

)

;given a and b, adds the numbers and returns the result of is_even
; if either a or b is null, then it will return null
#is_sum_even
Expand Down
104 changes: 52 additions & 52 deletions examples/conways_game_of_life/game_of_life.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,52 @@
))

;create some initial 'life'
;glider
    (assign (assoc
        board_map
            (set board_map
                (list 0 4) 1
                (list 1 4) 1
                (list 2 4) 1
                (list 2 3) 1
                (list 1 2) 1
            )
    ))

    ;oscillator
    (assign (assoc
        board_map
            (set board_map
                (list 30 44) 1
                (list 31 44) 1
                (list 32 44) 1
            )
    ))

    ;still
    (assign (assoc
        board_map
            (set board_map
                (list 70 24) 1
                (list 71 23) 1
                (list 71 25) 1
                (list 72 24) 1
            )
    ))

    ;acorn methuseiah
    (assign (assoc
        board_map
            (set board_map
                (list 50 15) 1
                (list 52 14) 1
                (list 52 15) 1
                (list 51 17) 1
                (list 52 18) 1
                (list 52 19) 1
                (list 52 20) 1
            )
    ))
;glider
(assign (assoc
board_map
(set board_map
[ 0 4 ] 1
[ 1 4 ] 1
[ 2 4 ] 1
[ 2 3 ] 1
[ 1 2 ] 1
)
))

;oscillator
(assign (assoc
board_map
(set board_map
[ 30 44 ] 1
[ 31 44 ] 1
[ 32 44 ] 1
)
))

;still
(assign (assoc
board_map
(set board_map
[ 70 24 ] 1
[ 71 23 ] 1
[ 71 25 ] 1
[ 72 24 ] 1
)
))

;acorn methuseiah
(assign (assoc
board_map
(set board_map
[ 50 15 ] 1
[ 52 14 ] 1
[ 52 15 ] 1
[ 51 17 ] 1
[ 52 18 ] 1
[ 52 19 ] 1
[ 52 20 ] 1
)
))

;any live cell with two or three live neighbours survives.
;any dead cell with three live neighbours becomes a live cell.
Expand Down Expand Up @@ -105,8 +105,8 @@
(map
(lambda (seq
(map
(lambda (print (if (target_value) " X" " -") ) )
(target_value)
(lambda (print (if (current_value) " X" " -") ) )
(current_value)
)
(print "\n")
))
Expand All @@ -118,15 +118,15 @@
||(map
(lambda (let
(assoc
row_index (target_index 1)
row (target_value 1)
row_index (current_index 1)
row (current_value 1)
)

(map
(lambda (let
(assoc
col_index (target_index 1)
cell (target_value 1)
col_index (current_index 1)
cell (current_value 1)
num_neighbors 0
)

Expand Down
Loading

0 comments on commit 42ebdba

Please sign in to comment.