diff --git a/AMALGAM-BEGINNER-GUIDE.md b/AMALGAM-BEGINNER-GUIDE.md index d9b31c2c..5a142a0f 100644 --- a/AMALGAM-BEGINNER-GUIDE.md +++ b/AMALGAM-BEGINNER-GUIDE.md @@ -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: @@ -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: @@ -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 @@ -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"] )) ) @@ -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: @@ -255,14 +255,14 @@ 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 ) @@ -270,7 +270,7 @@ More examples with descriptions: ;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 @@ -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: @@ -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 @@ -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 @@ -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 diff --git a/examples/api_discovery/number_services.amlg b/examples/api_discovery/number_services.amlg index 66f5d1c9..7deb8068 100644 --- a/examples/api_discovery/number_services.amlg +++ b/examples/api_discovery/number_services.amlg @@ -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, @@ -49,30 +49,30 @@ ; 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 @@ -80,11 +80,11 @@ ;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 diff --git a/examples/conways_game_of_life/game_of_life.amlg b/examples/conways_game_of_life/game_of_life.amlg index 2aa156ef..bb15a8d3 100644 --- a/examples/conways_game_of_life/game_of_life.amlg +++ b/examples/conways_game_of_life/game_of_life.amlg @@ -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. @@ -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") )) @@ -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 ) diff --git a/examples/fractals/mandelbrot_set.amlg b/examples/fractals/mandelbrot_set.amlg index df7f8b8c..a4233fda 100644 --- a/examples/fractals/mandelbrot_set.amlg +++ b/examples/fractals/mandelbrot_set.amlg @@ -31,14 +31,14 @@ (map (lambda (let (assoc - row (target_index 1) - row_pixels (target_value 1) + row (current_index 1) + row_pixels (current_value 1) ) (map (lambda (let (assoc - col (target_index 1) + col (current_index 1) pixel 0 old_x 0 old_y 0 @@ -96,8 +96,8 @@ (map (lambda (seq (map - (lambda (print (if (target_value) " X" " -") ) ) - (target_value) + (lambda (print (if (current_value) " X" " -") ) ) + (current_value) ) (print "\n") )) diff --git a/examples/json_search/json-search.amlg b/examples/json_search/json-search.amlg index 18e9b4a3..ab9649c7 100644 --- a/examples/json_search/json-search.amlg +++ b/examples/json_search/json-search.amlg @@ -17,13 +17,13 @@ ) ) (declare (assoc source_data (load source_file))) - + (declare (assoc edit_dist (map (lambda (let (assoc - cur_file (concat (target_value 1)) - cur_data (load (target_value 1)) + cur_file (concat (current_value 1)) + cur_data (load (current_value 1)) ) (list cur_file (edit_distance source_data cur_data)) @@ -32,25 +32,25 @@ json_files ) )) - + ;sort by edit distance (assign (assoc edit_dist - (sort (lambda (- (get (target_value) 1) (get (target_value 1) 1) )) edit_dist) + (sort (lambda (- (get (current_value) 1) (get (current_value 1) 1) )) edit_dist) )) - + (print "*** exact matches:\n") (map (lambda - (print (get (target_value) 0) "\n") + (print (get (current_value) 0) "\n") ) - - (filter (lambda (= (get (target_value) 1) 0)) edit_dist) + + (filter (lambda (= (get (current_value) 1) 0)) edit_dist) ) - + (print "*** best nonexact matches:\n") (map (lambda - (print (get (target_value) 0) "\n") + (print (get (current_value) 0) "\n") ) - - (trunc (filter (lambda (> (get (target_value) 1) 0)) edit_dist) 5) + + (trunc (filter (lambda (> (get (current_value) 1) 0)) edit_dist) 5) ) ) \ No newline at end of file