Couple of fixes to example programs.
This commit is contained in:
Kartik K. Agaram 2016-11-22 11:14:43 -08:00
parent 79cb6ea54e
commit 93c9862fa7
4 changed files with 44 additions and 42 deletions

View File

@ -44,7 +44,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
2:@:char/<span class="Special">raw</span> <span class="Special">&lt;-</span> copy *1:text/<span class="Special">raw</span>
]
memory-should-contain [
2:@:char <span class="Special">&lt;-</span> <span class="Constant">[t1 &lt;- multiply b c</span>
2:array:character <span class="Special">&lt;-</span> <span class="Constant">[t1 &lt;- multiply b c</span>
<span class="Constant">result &lt;- add a t1]</span>
]
]
@ -357,7 +357,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
11:@:char/<span class="Special">raw</span> <span class="Special">&lt;-</span> copy *s2
memory-should-contain [
<span class="Constant"> 10</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># parse result is an atom</span>
11:@:char <span class="Special">&lt;-</span> <span class="Constant">[a]</span>
11:array:character <span class="Special">&lt;-</span> <span class="Constant">[a]</span>
]
]
@ -369,7 +369,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
11:@:char/<span class="Special">raw</span> <span class="Special">&lt;-</span> copy *s2
memory-should-contain [
<span class="Constant"> 10</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># parse result is an atom</span>
11:@:char <span class="Special">&lt;-</span> <span class="Constant">[abc]</span>
11:array:character <span class="Special">&lt;-</span> <span class="Constant">[abc]</span>
]
]
@ -396,8 +396,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
<span class="Constant"> 12</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest is a pair</span>
<span class="Constant"> 13</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.first is an atom</span>
<span class="Constant"> 14</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span> <span class="Comment"># result.rest.rest is nil</span>
20:@:char <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span>
30:@:char <span class="Special">&lt;-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span>
20:array:character <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span>
30:array:character <span class="Special">&lt;-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span>
]
]
@ -424,8 +424,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
<span class="Constant"> 12</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest is a pair</span>
<span class="Constant"> 13</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.first is an atom</span>
<span class="Constant"> 14</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span> <span class="Comment"># result.rest.rest is nil</span>
20:@:char <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span>
30:@:char <span class="Special">&lt;-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span>
20:array:character <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span>
30:array:character <span class="Special">&lt;-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span>
]
]
@ -459,9 +459,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
<span class="Constant"> 14</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.rest is a pair</span>
<span class="Constant"> 15</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.rest.first is an atom</span>
<span class="Constant"> 16</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span> <span class="Comment"># result.rest.rest.rest is nil</span>
20:@:char <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span>
30:@:char <span class="Special">&lt;-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span>
40:@:char <span class="Special">&lt;-</span> <span class="Constant">[ghi]</span> <span class="Comment"># result.rest.rest</span>
20:array:character <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span>
30:array:character <span class="Special">&lt;-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span>
40:array:character <span class="Special">&lt;-</span> <span class="Constant">[ghi]</span> <span class="Comment"># result.rest.rest</span>
]
]
@ -486,7 +486,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
<span class="Constant"> 12</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.first.first is an atom</span>
<span class="Constant"> 13</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span> <span class="Comment"># result.first.rest is nil</span>
<span class="Constant"> 14</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span> <span class="Comment"># result.rest is nil</span>
20:@:char <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first.first</span>
20:array:character <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first.first</span>
]
]
@ -516,8 +516,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
<span class="Constant"> 13</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span> <span class="Comment"># result.first.rest is nil</span>
<span class="Constant"> 14</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.first is an atom</span>
<span class="Constant"> 15</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span> <span class="Comment"># result.rest.rest is nil</span>
20:@:char <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first.first</span>
30:@:char <span class="Special">&lt;-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span>
20:array:character <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first.first</span>
30:array:character <span class="Special">&lt;-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span>
]
]
@ -564,8 +564,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
<span class="Constant"> 10</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># parse result is a pair</span>
<span class="Constant"> 11</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.first is an atom</span>
<span class="Constant"> 12</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest is an atom</span>
20:@:char <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span>
30:@:char <span class="Special">&lt;-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest</span>
20:array:character <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span>
30:array:character <span class="Special">&lt;-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest</span>
]
]
@ -594,9 +594,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
<span class="Constant"> 12</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest is a pair</span>
<span class="Constant"> 13</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.first is an atom</span>
<span class="Constant"> 14</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span> <span class="Comment"># result.rest.rest is an atom</span>
20:@:char <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span>
30:@:char <span class="Special">&lt;-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span>
40:@:char <span class="Special">&lt;-</span> <span class="Constant">[ghi]</span> <span class="Comment"># result.rest.rest</span>
20:array:character <span class="Special">&lt;-</span> <span class="Constant">[abc]</span> <span class="Comment"># result.first</span>
30:array:character <span class="Special">&lt;-</span> <span class="Constant">[def]</span> <span class="Comment"># result.rest.first</span>
40:array:character <span class="Special">&lt;-</span> <span class="Constant">[ghi]</span> <span class="Comment"># result.rest.rest</span>
]
]

View File

@ -41,7 +41,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
file:num
]
<span class="muRecipe">def</span> nqueens n:num, queens:&amp;:list:square<span class="muRecipe"> -&gt; </span>result:num [
<span class="muRecipe">def</span> nqueens n:num, queens:&amp;:list:square<span class="muRecipe"> -&gt; </span>result:num, queens:&amp;:list:square [
<span class="Constant">local-scope</span>
<span class="Constant">load-ingredients</span>
<span class="Comment"># if 'queens' is already long enough, print it and return</span>
@ -69,9 +69,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
<span class="Delimiter">{</span>
curr-conflicts?:bool <span class="Special">&lt;-</span> conflict? curr, queens
<span class="muControl">break-if</span> curr-conflicts?
new-queens:&amp;:list:square <span class="Special">&lt;-</span> push curr, queens
sub-result:num <span class="Special">&lt;-</span> nqueens n, new-queens
queens:&amp;:list:square <span class="Special">&lt;-</span> push curr, queens
sub-result:num <span class="Special">&lt;-</span> nqueens n, queens
result <span class="Special">&lt;-</span> add result, sub-result
queens <span class="Special">&lt;-</span> rest queens
<span class="Delimiter">}</span>
next-file <span class="Special">&lt;-</span> add next-file,<span class="Constant"> 1</span>
<span class="muControl">loop</span>

View File

@ -8,7 +8,7 @@ scenario convert-lambda [
2:@:char/raw <- copy *1:text/raw
]
memory-should-contain [
2:@:char <- [t1 <- multiply b c
2:array:character <- [t1 <- multiply b c
result <- add a t1]
]
]
@ -321,7 +321,7 @@ scenario parse-single-letter-atom [
11:@:char/raw <- copy *s2
memory-should-contain [
10 <- 1 # parse result is an atom
11:@:char <- [a]
11:array:character <- [a]
]
]
@ -333,7 +333,7 @@ scenario parse-atom [
11:@:char/raw <- copy *s2
memory-should-contain [
10 <- 1 # parse result is an atom
11:@:char <- [abc]
11:array:character <- [abc]
]
]
@ -360,8 +360,8 @@ scenario parse-list-of-two-atoms [
12 <- 1 # result.rest is a pair
13 <- 1 # result.rest.first is an atom
14 <- 0 # result.rest.rest is nil
20:@:char <- [abc] # result.first
30:@:char <- [def] # result.rest.first
20:array:character <- [abc] # result.first
30:array:character <- [def] # result.rest.first
]
]
@ -388,8 +388,8 @@ scenario parse-list-with-extra-spaces [
12 <- 1 # result.rest is a pair
13 <- 1 # result.rest.first is an atom
14 <- 0 # result.rest.rest is nil
20:@:char <- [abc] # result.first
30:@:char <- [def] # result.rest.first
20:array:character <- [abc] # result.first
30:array:character <- [def] # result.rest.first
]
]
@ -423,9 +423,9 @@ scenario parse-list-of-more-than-two-atoms [
14 <- 1 # result.rest.rest is a pair
15 <- 1 # result.rest.rest.first is an atom
16 <- 0 # result.rest.rest.rest is nil
20:@:char <- [abc] # result.first
30:@:char <- [def] # result.rest.first
40:@:char <- [ghi] # result.rest.rest
20:array:character <- [abc] # result.first
30:array:character <- [def] # result.rest.first
40:array:character <- [ghi] # result.rest.rest
]
]
@ -450,7 +450,7 @@ scenario parse-nested-list [
12 <- 1 # result.first.first is an atom
13 <- 0 # result.first.rest is nil
14 <- 0 # result.rest is nil
20:@:char <- [abc] # result.first.first
20:array:character <- [abc] # result.first.first
]
]
@ -480,8 +480,8 @@ scenario parse-nested-list-2 [
13 <- 0 # result.first.rest is nil
14 <- 1 # result.rest.first is an atom
15 <- 0 # result.rest.rest is nil
20:@:char <- [abc] # result.first.first
30:@:char <- [def] # result.rest.first
20:array:character <- [abc] # result.first.first
30:array:character <- [def] # result.rest.first
]
]
@ -528,8 +528,8 @@ scenario parse-dotted-list-of-two-atoms [
10 <- 1 # parse result is a pair
11 <- 1 # result.first is an atom
12 <- 1 # result.rest is an atom
20:@:char <- [abc] # result.first
30:@:char <- [def] # result.rest
20:array:character <- [abc] # result.first
30:array:character <- [def] # result.rest
]
]
@ -558,9 +558,9 @@ scenario parse-dotted-list-of-more-than-two-atoms [
12 <- 1 # result.rest is a pair
13 <- 1 # result.rest.first is an atom
14 <- 1 # result.rest.rest is an atom
20:@:char <- [abc] # result.first
30:@:char <- [def] # result.rest.first
40:@:char <- [ghi] # result.rest.rest
20:array:character <- [abc] # result.first
30:array:character <- [def] # result.rest.first
40:array:character <- [ghi] # result.rest.rest
]
]

View File

@ -8,7 +8,7 @@ container square [
file:num
]
def nqueens n:num, queens:&:list:square -> result:num [
def nqueens n:num, queens:&:list:square -> result:num, queens:&:list:square [
local-scope
load-ingredients
# if 'queens' is already long enough, print it and return
@ -36,9 +36,10 @@ def nqueens n:num, queens:&:list:square -> result:num [
{
curr-conflicts?:bool <- conflict? curr, queens
break-if curr-conflicts?
new-queens:&:list:square <- push curr, queens
sub-result:num <- nqueens n, new-queens
queens:&:list:square <- push curr, queens
sub-result:num <- nqueens n, queens
result <- add result, sub-result
queens <- rest queens
}
next-file <- add next-file, 1
loop