This commit is contained in:
Kartik K. Agaram 2016-10-08 10:52:58 -07:00
parent 0d6630f075
commit 9458918f9e
9 changed files with 111 additions and 111 deletions

View File

@ -7,7 +7,7 @@ def producer sink:&:sink:char -> sink:&:sink:char [
# n = 0
n:char <- copy 0
{
done?:boolean <- lesser-than n, 5
done?:bool <- lesser-than n, 5
break-unless done?
# other threads might get between these prints
$print [produce: ], n, [
@ -25,7 +25,7 @@ def consumer source:&:source:char -> source:&:source:char [
load-ingredients
{
# read an integer from the channel
n:char, eof?:boolean, source <- read source
n:char, eof?:bool, source <- read source
break-if eof?
# other threads might get between these prints
$print [consume: ], n:char, [

View File

@ -88,7 +88,7 @@ def chessboard screen:&:screen, console:&:console -> screen:&:screen, console:&:
{
cursor-to-next-line screen
screen <- print screen, [move: ]
m:&:move, quit:boolean, error:boolean <- read-move buffered-stdin-in, screen
m:&:move, quit:bool, error:bool <- read-move buffered-stdin-in, screen
break-if quit, +quit:label
buffered-stdin-in <- clear buffered-stdin-in # cleanup after error. todo: test this?
loop-if error
@ -107,13 +107,13 @@ def new-board initial-position:&:@:char -> board:board [
load-ingredients
# assert(length(initial-position) == 64)
len:num <- length *initial-position
correct-length?:boolean <- equal len, 64
correct-length?:bool <- equal len, 64
assert correct-length?, [chessboard had incorrect size]
# board is an array of pointers to files; file is an array of characters
board <- new {(address array character): type}, 8
col:num <- copy 0
{
done?:boolean <- equal col, 8
done?:bool <- equal col, 8
break-if done?
file:&:@:char <- new-file initial-position, col
*board <- put-index *board, col, file
@ -129,7 +129,7 @@ def new-file position:&:@:char, index:num -> result:&:@:char [
result <- new character:type, 8
row:num <- copy 0
{
done?:boolean <- equal row, 8
done?:bool <- equal row, 8
break-if done?
square:char <- index *position, index
*result <- put-index *result, row, square
@ -146,7 +146,7 @@ def print-board screen:&:screen, board:board -> screen:&:screen [
space:char <- copy 32/space
# print each row
{
done?:boolean <- lesser-than row, 0
done?:bool <- lesser-than row, 0
break-if done?
# print rank number as a legend
rank:num <- add row, 1
@ -155,8 +155,8 @@ def print-board screen:&:screen, board:board -> screen:&:screen [
# print each square in the row
col:num <- copy 0
{
done?:boolean <- equal col:num, 8
break-if done?:boolean
done?:bool <- equal col:num, 8
break-if done?:bool
f:&:@:char <- index *board, col
c:char <- index *f, row
print screen, c
@ -233,10 +233,10 @@ container move [
]
# prints only error messages to screen
def read-move stdin:&:source:char, screen:&:screen -> result:&:move, quit?:boolean, error?:boolean, stdin:&:source:char, screen:&:screen [
def read-move stdin:&:source:char, screen:&:screen -> result:&:move, quit?:bool, error?:bool, stdin:&:source:char, screen:&:screen [
local-scope
load-ingredients
from-file:num, quit?:boolean, error?:boolean <- read-file stdin, screen
from-file:num, quit?:bool, error?:bool <- read-file stdin, screen
return-if quit?, 0/dummy
return-if error?, 0/dummy
# construct the move object
@ -249,8 +249,8 @@ def read-move stdin:&:source:char, screen:&:screen -> result:&:move, quit?:boole
error? <- expect-from-channel stdin, 45/dash, screen
return-if error?, 0/dummy, 0/quit
to-file:num, quit?, error? <- read-file stdin, screen
return-if quit?:boolean, 0/dummy
return-if error?:boolean, 0/dummy
return-if quit?:bool, 0/dummy
return-if error?:bool, 0/dummy
*result <- put *result, to-file:offset, to-file
to-rank:num, quit?, error? <- read-rank stdin, screen
return-if quit?, 0/dummy
@ -261,13 +261,13 @@ def read-move stdin:&:source:char, screen:&:screen -> result:&:move, quit?:boole
]
# valid values for file: 0-7
def read-file stdin:&:source:char, screen:&:screen -> file:num, quit:boolean, error:boolean, stdin:&:source:char, screen:&:screen [
def read-file stdin:&:source:char, screen:&:screen -> file:num, quit:bool, error:bool, stdin:&:source:char, screen:&:screen [
local-scope
load-ingredients
c:char, eof?:boolean, stdin <- read stdin
c:char, eof?:bool, stdin <- read stdin
return-if eof?, 0/dummy, 1/quit, 0/error
{
q-pressed?:boolean <- equal c, 81/Q
q-pressed?:bool <- equal c, 81/Q
break-unless q-pressed?
return 0/dummy, 1/quit, 0/error
}
@ -277,12 +277,12 @@ def read-file stdin:&:source:char, screen:&:screen -> file:num, quit:boolean, er
return 0/dummy, 1/quit, 0/error
}
{
empty-fake-keyboard?:boolean <- equal c, 0/eof
empty-fake-keyboard?:bool <- equal c, 0/eof
break-unless empty-fake-keyboard?
return 0/dummy, 1/quit, 0/error
}
{
newline?:boolean <- equal c, 10/newline
newline?:bool <- equal c, 10/newline
break-unless newline?
print screen, [that's not enough]
return 0/dummy, 0/quit, 1/error
@ -290,7 +290,7 @@ def read-file stdin:&:source:char, screen:&:screen -> file:num, quit:boolean, er
file:num <- subtract c, 97/a
# 'a' <= file <= 'h'
{
above-min:boolean <- greater-or-equal file, 0
above-min:bool <- greater-or-equal file, 0
break-if above-min
print screen, [file too low: ]
print screen, c
@ -298,7 +298,7 @@ def read-file stdin:&:source:char, screen:&:screen -> file:num, quit:boolean, er
return 0/dummy, 0/quit, 1/error
}
{
below-max:boolean <- lesser-than file, 8
below-max:bool <- lesser-than file, 8
break-if below-max
print screen, [file too high: ]
print screen, c
@ -308,13 +308,13 @@ def read-file stdin:&:source:char, screen:&:screen -> file:num, quit:boolean, er
]
# valid values for rank: 0-7
def read-rank stdin:&:source:char, screen:&:screen -> rank:num, quit?:boolean, error?:boolean, stdin:&:source:char, screen:&:screen [
def read-rank stdin:&:source:char, screen:&:screen -> rank:num, quit?:bool, error?:bool, stdin:&:source:char, screen:&:screen [
local-scope
load-ingredients
c:char, eof?:boolean, stdin <- read stdin
c:char, eof?:bool, stdin <- read stdin
return-if eof?, 0/dummy, 1/quit, 0/error
{
q-pressed?:boolean <- equal c, 8/Q
q-pressed?:bool <- equal c, 8/Q
break-unless q-pressed?
return 0/dummy, 1/quit, 0/error
}
@ -324,7 +324,7 @@ def read-rank stdin:&:source:char, screen:&:screen -> rank:num, quit?:boolean, e
return 0/dummy, 1/quit, 0/error
}
{
newline?:boolean <- equal c, 10 # newline
newline?:bool <- equal c, 10 # newline
break-unless newline?
print screen, [that's not enough]
return 0/dummy, 0/quit, 1/error
@ -332,14 +332,14 @@ def read-rank stdin:&:source:char, screen:&:screen -> rank:num, quit?:boolean, e
rank:num <- subtract c, 49/'1'
# assert'1' <= rank <= '8'
{
above-min:boolean <- greater-or-equal rank, 0
above-min:bool <- greater-or-equal rank, 0
break-if above-min
print screen, [rank too low: ]
print screen, c
return 0/dummy, 0/quit, 1/error
}
{
below-max:boolean <- lesser-or-equal rank, 7
below-max:bool <- lesser-or-equal rank, 7
break-if below-max
print screen, [rank too high: ]
print screen, c
@ -350,13 +350,13 @@ def read-rank stdin:&:source:char, screen:&:screen -> rank:num, quit?:boolean, e
# read a character from the given channel and check that it's what we expect
# return true on error
def expect-from-channel stdin:&:source:char, expected:char, screen:&:screen -> result:boolean, stdin:&:source:char, screen:&:screen [
def expect-from-channel stdin:&:source:char, expected:char, screen:&:screen -> result:bool, stdin:&:source:char, screen:&:screen [
local-scope
load-ingredients
c:char, eof?:boolean, stdin <- read stdin
c:char, eof?:bool, stdin <- read stdin
return-if eof? 1/true
{
match?:boolean <- equal c, expected
match?:bool <- equal c, expected
break-if match?
print screen, [expected character not found]
}
@ -372,7 +372,7 @@ scenario read-move-blocking [
# 'read-move' is waiting for input
wait-for-routine-to-block read-move-routine
read-move-state:num <- routine-state read-move-routine
waiting?:boolean <- not-equal read-move-state, 2/discontinued
waiting?:bool <- not-equal read-move-state, 2/discontinued
assert waiting?, [
F read-move-blocking: routine failed to pause after coming up (before any keys were pressed)]
# press 'a'
@ -426,7 +426,7 @@ F read-move-blocking: routine failed to pause after file 'a2-a4']
# 'read-move' now completes
wait-for-routine-to-block read-move-routine
read-move-state <- routine-state read-move-routine
completed?:boolean <- equal read-move-state, 1/completed
completed?:bool <- equal read-move-state, 1/completed
assert completed?, [
F read-move-blocking: routine failed to terminate on newline]
trace 1, [test], [reached end]
@ -445,7 +445,7 @@ scenario read-move-quit [
# 'read-move' is waiting for input
wait-for-routine-to-block read-move-routine
read-move-state:num <- routine-state read-move-routine
waiting?:boolean <- not-equal read-move-state, 2/discontinued
waiting?:bool <- not-equal read-move-state, 2/discontinued
assert waiting?, [
F read-move-quit: routine failed to pause after coming up (before any keys were pressed)]
# press 'q'
@ -454,7 +454,7 @@ F read-move-quit: routine failed to pause after coming up (before any keys were
# 'read-move' completes
wait-for-routine-to-block read-move-routine
read-move-state <- routine-state read-move-routine
completed?:boolean <- equal read-move-state, 1/completed
completed?:bool <- equal read-move-state, 1/completed
assert completed?, [
F read-move-quit: routine failed to terminate on 'q']
trace 1, [test], [reached end]
@ -473,7 +473,7 @@ scenario read-move-illegal-file [
# 'read-move' is waiting for input
wait-for-routine-to-block read-move-routine
read-move-state:num <- routine-state read-move-routine
waiting?:boolean <- not-equal read-move-state, 2/discontinued
waiting?:bool <- not-equal read-move-state, 2/discontinued
assert waiting?, [
F read-move-illegal-file: routine failed to pause after coming up (before any keys were pressed)]
sink <- write sink, 50/'2'
@ -495,7 +495,7 @@ scenario read-move-illegal-rank [
# 'read-move' is waiting for input
wait-for-routine-to-block read-move-routine
read-move-state:num <- routine-state read-move-routine
waiting?:boolean <- not-equal read-move-state, 2/discontinued
waiting?:bool <- not-equal read-move-state, 2/discontinued
assert waiting?, [
F read-move-illegal-rank: routine failed to pause after coming up (before any keys were pressed)]
sink <- write sink, 97/a
@ -518,7 +518,7 @@ scenario read-move-empty [
# 'read-move' is waiting for input
wait-for-routine-to-block read-move-routine
read-move-state:num <- routine-state read-move-routine
waiting?:boolean <- not-equal read-move-state, 2/discontinued
waiting?:bool <- not-equal read-move-state, 2/discontinued
assert waiting?, [
F read-move-empty: routine failed to pause after coming up (before any keys were pressed)]
sink <- write sink, 10/newline

View File

@ -6,7 +6,7 @@ def main [
local-scope
open-console
{
e:event, found?:boolean <- check-for-interaction
e:event, found?:bool <- check-for-interaction
break-if found?
print-character-to-display 97, 7/white
loop

View File

@ -12,7 +12,7 @@ def factorial n:num -> result:num [
load-ingredients
{
# if n=0 return 1
zero?:boolean <- equal n, 0
zero?:bool <- equal n, 0
break-unless zero?
return 1
}

View File

@ -8,7 +8,7 @@ def main [
source-file:&:source:char <- start-reading 0/real-filesystem, [/tmp/mu-x]
sink-file:&:sink:char, write-routine:num <- start-writing 0/real-filesystem, [/tmp/mu-y]
{
c:char, done?:boolean, source-file <- read source-file
c:char, done?:bool, source-file <- read source-file
break-if done?
sink-file <- write sink-file, c
loop

View File

@ -47,14 +47,14 @@ def new-pair a:&:cell, b:&:cell -> result:&:cell [
*result <- merge 1/tag:pair, a/first, b/rest
]
def is-atom? x:&:cell -> result:boolean [
def is-atom? x:&:cell -> result:bool [
local-scope
load-ingredients
reply-unless x, 0/false
_, result <- maybe-convert *x, atom:variant
]
def is-pair? x:&:cell -> result:boolean [
def is-pair? x:&:cell -> result:bool [
local-scope
load-ingredients
reply-unless x, 0/false
@ -65,8 +65,8 @@ scenario atom-is-not-pair [
local-scope
s:text <- new [a]
x:&:cell <- new-atom s
10:boolean/raw <- is-atom? x
11:boolean/raw <- is-pair? x
10:bool/raw <- is-atom? x
11:bool/raw <- is-pair? x
memory-should-contain [
10 <- 1
11 <- 0
@ -79,18 +79,18 @@ scenario pair-is-not-atom [
s:text <- new [a]
x:&:cell <- new-atom s
y:&:cell <- new-pair x, 0/nil
10:boolean/raw <- is-atom? y
11:boolean/raw <- is-pair? y
10:bool/raw <- is-atom? y
11:bool/raw <- is-pair? y
memory-should-contain [
10 <- 0
11 <- 1
]
]
def atom-match? x:&:cell, pat:text -> result:boolean [
def atom-match? x:&:cell, pat:text -> result:bool [
local-scope
load-ingredients
s:text, is-atom?:boolean <- maybe-convert *x, atom:variant
s:text, is-atom?:bool <- maybe-convert *x, atom:variant
reply-unless is-atom?, 0/false
result <- equal pat, s
]
@ -98,7 +98,7 @@ def atom-match? x:&:cell, pat:text -> result:boolean [
scenario atom-match [
local-scope
x:&:cell <- new-atom [abc]
10:boolean/raw <- atom-match? x, [abc]
10:bool/raw <- atom-match? x, [abc]
memory-should-contain [
10 <- 1
]
@ -107,7 +107,7 @@ scenario atom-match [
def first x:&:cell -> result:&:cell [
local-scope
load-ingredients
pair:pair, pair?:boolean <- maybe-convert *x, pair:variant
pair:pair, pair?:bool <- maybe-convert *x, pair:variant
reply-unless pair?, 0/nil
result <- get pair, first:offset
]
@ -115,7 +115,7 @@ def first x:&:cell -> result:&:cell [
def rest x:&:cell -> result:&:cell [
local-scope
load-ingredients
pair:pair, pair?:boolean <- maybe-convert *x, pair:variant
pair:pair, pair?:bool <- maybe-convert *x, pair:variant
reply-unless pair?, 0/nil
result <- get pair, rest:offset
]
@ -123,7 +123,7 @@ def rest x:&:cell -> result:&:cell [
def set-first base:&:cell, new-first:&:cell -> base:&:cell [
local-scope
load-ingredients
pair:pair, is-pair?:boolean <- maybe-convert *base, pair:variant
pair:pair, is-pair?:bool <- maybe-convert *base, pair:variant
reply-unless is-pair?
pair <- put pair, first:offset, new-first
*base <- merge 1/pair, pair
@ -132,7 +132,7 @@ def set-first base:&:cell, new-first:&:cell -> base:&:cell [
def set-rest base:&:cell, new-rest:&:cell -> base:&:cell [
local-scope
load-ingredients
pair:pair, is-pair?:boolean <- maybe-convert *base, pair:variant
pair:pair, is-pair?:bool <- maybe-convert *base, pair:variant
reply-unless is-pair?
pair <- put pair, rest:offset, new-rest
*base <- merge 1/pair, pair
@ -157,7 +157,7 @@ scenario cell-operations-on-pair [
x:&:cell <- new-atom s
y:&:cell <- new-pair x, 0/nil
x2:&:cell <- first y
10:boolean/raw <- equal x, x2
10:bool/raw <- equal x, x2
11:&:cell/raw <- rest y
memory-should-contain [
10 <- 1 # first is correct
@ -180,15 +180,15 @@ def parse in:&:stream:char -> out:&:cell, in:&:stream:char [
load-ingredients
# skip whitespace
in <- skip-whitespace in
c:char, eof?:boolean <- peek in
c:char, eof?:bool <- peek in
reply-if eof?, 0/nil
pair?:boolean <- equal c, 40/open-paren
pair?:bool <- equal c, 40/open-paren
{
break-if pair?
# atom
b:&:buffer <- new-buffer 30
{
done?:boolean <- end-of-stream? in
done?:bool <- end-of-stream? in
break-if done?
# stop before close paren or space
c:char <- peek in
@ -210,11 +210,11 @@ def parse in:&:stream:char -> out:&:cell, in:&:stream:char [
out <- new cell:type # start out with nil
# read in first element of pair
{
end?:boolean <- end-of-stream? in
not-end?:boolean <- not end?
end?:bool <- end-of-stream? in
not-end?:bool <- not end?
assert not-end?, [unbalanced '(' in expression]
c <- peek in
close-paren?:boolean <- equal c, 41/close-paren
close-paren?:bool <- equal c, 41/close-paren
break-if close-paren?
first:&:cell, in <- parse in
*out <- merge 1/pair, first, 0/nil
@ -223,20 +223,20 @@ def parse in:&:stream:char -> out:&:cell, in:&:stream:char [
curr:&:cell <- copy out
{
in <- skip-whitespace in
end?:boolean <- end-of-stream? in
not-end?:boolean <- not end?
end?:bool <- end-of-stream? in
not-end?:bool <- not end?
assert not-end?, [unbalanced '(' in expression]
# termination check: ')'
c <- peek in
{
close-paren?:boolean <- equal c, 41/close-paren
close-paren?:bool <- equal c, 41/close-paren
break-unless close-paren?
read in # skip ')'
break +end-pair:label
}
# still here? read next element of pair
next:&:cell, in <- parse in
is-dot?:boolean <- atom-match? next, [.]
is-dot?:bool <- atom-match? next, [.]
{
break-if is-dot?
next-curr:&:cell <- new-pair next, 0/nil
@ -248,7 +248,7 @@ def parse in:&:stream:char -> out:&:cell, in:&:stream:char [
# deal with dotted pair
in <- skip-whitespace in
c <- peek in
not-close-paren?:boolean <- not-equal c, 41/close-paren
not-close-paren?:bool <- not-equal c, 41/close-paren
assert not-close-paren?, [')' cannot immediately follow '.']
final:&:cell <- parse in
curr <- set-rest curr, final
@ -256,7 +256,7 @@ def parse in:&:stream:char -> out:&:cell, in:&:stream:char [
# is going to end the pair
in <- skip-whitespace in
c <- peek in
close-paren?:boolean <- equal c, 41/close-paren
close-paren?:bool <- equal c, 41/close-paren
assert close-paren?, ['.' must be followed by exactly one expression before ')']
}
loop
@ -269,10 +269,10 @@ def skip-whitespace in:&:stream:char -> in:&:stream:char [
local-scope
load-ingredients
{
done?:boolean <- end-of-stream? in
done?:bool <- end-of-stream? in
reply-if done?, 0/null
c:char <- peek in
space?:boolean <- space? c
space?:bool <- space? c
break-unless space?
read in # skip
loop
@ -298,7 +298,7 @@ def to-buffer x:&:cell, buf:&:buffer -> buf:&:buffer [
}
# base case: atom
{
s:text, atom?:boolean <- maybe-convert *x, atom:variant
s:text, atom?:bool <- maybe-convert *x, atom:variant
break-unless atom?
buf <- append buf, s
reply
@ -317,7 +317,7 @@ scenario parse-single-letter-atom [
local-scope
s:text <- new [a]
x:&:cell <- parse s
s2:text, 10:boolean/raw <- maybe-convert *x, atom:variant
s2:text, 10:bool/raw <- maybe-convert *x, atom:variant
11:@:char/raw <- copy *s2
memory-should-contain [
10 <- 1 # parse result is an atom
@ -329,7 +329,7 @@ scenario parse-atom [
local-scope
s:text <- new [abc]
x:&:cell <- parse s
s2:text, 10:boolean/raw <- maybe-convert *x, atom:variant
s2:text, 10:bool/raw <- maybe-convert *x, atom:variant
11:@:char/raw <- copy *s2
memory-should-contain [
10 <- 1 # parse result is an atom
@ -344,13 +344,13 @@ scenario parse-list-of-two-atoms [
trace-should-contain [
app/parse: < abc | < def | <> > >
]
10:boolean/raw <- is-pair? x
10:bool/raw <- is-pair? x
x1:&:cell <- first x
x2:&:cell <- rest x
s1:text, 11:boolean/raw <- maybe-convert *x1, atom:variant
12:boolean/raw <- is-pair? x2
s1:text, 11:bool/raw <- maybe-convert *x1, atom:variant
12:bool/raw <- is-pair? x2
x3:&:cell <- first x2
s2:text, 13:boolean/raw <- maybe-convert *x3, atom:variant
s2:text, 13:bool/raw <- maybe-convert *x3, atom:variant
14:&:cell/raw <- rest x2
20:@:char/raw <- copy *s1
30:@:char/raw <- copy *s2
@ -372,13 +372,13 @@ scenario parse-list-with-extra-spaces [
trace-should-contain [
app/parse: < abc | < def | <> > >
]
10:boolean/raw <- is-pair? x
10:bool/raw <- is-pair? x
x1:&:cell <- first x
x2:&:cell <- rest x
s1:text, 11:boolean/raw <- maybe-convert *x1, atom:variant
12:boolean/raw <- is-pair? x2
s1:text, 11:bool/raw <- maybe-convert *x1, atom:variant
12:bool/raw <- is-pair? x2
x3:&:cell <- first x2
s2:text, 13:boolean/raw <- maybe-convert *x3, atom:variant
s2:text, 13:bool/raw <- maybe-convert *x3, atom:variant
14:&:cell/raw <- rest x2
20:@:char/raw <- copy *s1
30:@:char/raw <- copy *s2
@ -400,17 +400,17 @@ scenario parse-list-of-more-than-two-atoms [
trace-should-contain [
app/parse: < abc | < def | < ghi | <> > > >
]
10:boolean/raw <- is-pair? x
10:bool/raw <- is-pair? x
x1:&:cell <- first x
x2:&:cell <- rest x
s1:text, 11:boolean/raw <- maybe-convert *x1, atom:variant
12:boolean/raw <- is-pair? x2
s1:text, 11:bool/raw <- maybe-convert *x1, atom:variant
12:bool/raw <- is-pair? x2
x3:&:cell <- first x2
s2:text, 13:boolean/raw <- maybe-convert *x3, atom:variant
s2:text, 13:bool/raw <- maybe-convert *x3, atom:variant
x4:&:cell <- rest x2
14:boolean/raw <- is-pair? x4
14:bool/raw <- is-pair? x4
x5:&:cell <- first x4
s3:text, 15:boolean/raw <- maybe-convert *x5, atom:variant
s3:text, 15:bool/raw <- maybe-convert *x5, atom:variant
16:&:cell/raw <- rest x4
20:@:char/raw <- copy *s1
30:@:char/raw <- copy *s2
@ -436,11 +436,11 @@ scenario parse-nested-list [
trace-should-contain [
app/parse: < < abc | <> > | <> >
]
10:boolean/raw <- is-pair? x
10:bool/raw <- is-pair? x
x1:&:cell <- first x
11:boolean/raw <- is-pair? x
11:bool/raw <- is-pair? x
x2:&:cell <- first x1
s1:text, 12:boolean/raw <- maybe-convert *x2, atom:variant
s1:text, 12:bool/raw <- maybe-convert *x2, atom:variant
13:&:cell/raw <- rest x1
14:&:cell/raw <- rest x
20:@:char/raw <- copy *s1
@ -461,15 +461,15 @@ scenario parse-nested-list-2 [
trace-should-contain [
app/parse: < < abc | <> > | < def | <> > >
]
10:boolean/raw <- is-pair? x
10:bool/raw <- is-pair? x
x1:&:cell <- first x
11:boolean/raw <- is-pair? x
11:bool/raw <- is-pair? x
x2:&:cell <- first x1
s1:text, 12:boolean/raw <- maybe-convert *x2, atom:variant
s1:text, 12:bool/raw <- maybe-convert *x2, atom:variant
13:&:cell/raw <- rest x1
x3:&:cell <- rest x
x4:&:cell <- first x3
s2:text, 14:boolean/raw <- maybe-convert *x4, atom:variant
s2:text, 14:bool/raw <- maybe-convert *x4, atom:variant
15:&:cell/raw <- rest x3
20:@:char/raw <- copy *s1
30:@:char/raw <- copy *s2
@ -516,11 +516,11 @@ scenario parse-dotted-list-of-two-atoms [
trace-should-contain [
app/parse: < abc | def >
]
10:boolean/raw <- is-pair? x
10:bool/raw <- is-pair? x
x1:&:cell <- first x
x2:&:cell <- rest x
s1:text, 11:boolean/raw <- maybe-convert *x1, atom:variant
s2:text, 12:boolean/raw <- maybe-convert *x2, atom:variant
s1:text, 11:bool/raw <- maybe-convert *x1, atom:variant
s2:text, 12:bool/raw <- maybe-convert *x2, atom:variant
20:@:char/raw <- copy *s1
30:@:char/raw <- copy *s2
memory-should-contain [
@ -540,15 +540,15 @@ scenario parse-dotted-list-of-more-than-two-atoms [
trace-should-contain [
app/parse: < abc | < def | ghi > >
]
10:boolean/raw <- is-pair? x
10:bool/raw <- is-pair? x
x1:&:cell <- first x
x2:&:cell <- rest x
s1:text, 11:boolean/raw <- maybe-convert *x1, atom:variant
12:boolean/raw <- is-pair? x2
s1:text, 11:bool/raw <- maybe-convert *x1, atom:variant
12:bool/raw <- is-pair? x2
x3:&:cell <- first x2
s2:text, 13:boolean/raw <- maybe-convert *x3, atom:variant
s2:text, 13:bool/raw <- maybe-convert *x3, atom:variant
x4:&:cell <- rest x2
s3:text, 14:boolean/raw <- maybe-convert *x4, atom:variant
s3:text, 14:bool/raw <- maybe-convert *x4, atom:variant
20:@:char/raw <- copy *s1
30:@:char/raw <- copy *s2
40:@:char/raw <- copy *s3

View File

@ -14,7 +14,7 @@ def nqueens n:num, queens:&:list:square -> result:num [
# if 'queens' is already long enough, print it and return
added-so-far:num <- length queens
{
done?:boolean <- greater-or-equal added-so-far, n
done?:bool <- greater-or-equal added-so-far, n
break-unless done?
stash queens
return 1
@ -30,11 +30,11 @@ def nqueens n:num, queens:&:list:square -> result:num [
result <- copy 0
next-file:num <- copy 0
{
done?:boolean <- greater-or-equal next-file, n
done?:bool <- greater-or-equal next-file, n
break-if done?
curr:square <- merge next-rank, next-file
{
curr-conflicts?:boolean <- conflict? curr, queens
curr-conflicts?:bool <- conflict? curr, queens
break-if curr-conflicts?
new-queens:&:list:square <- push curr, queens
sub-result:num <- nqueens n, new-queens
@ -45,16 +45,16 @@ def nqueens n:num, queens:&:list:square -> result:num [
}
]
def conflict? curr:square, queens:&:list:square -> result:boolean [
def conflict? curr:square, queens:&:list:square -> result:bool [
local-scope
load-ingredients
result1:boolean <- conflicting-file? curr, queens
result1:bool <- conflicting-file? curr, queens
reply-if result1, result1
result2:boolean <- conflicting-diagonal? curr, queens
result2:bool <- conflicting-diagonal? curr, queens
reply result2
]
def conflicting-file? curr:square, queens:&:list:square -> result:boolean [
def conflicting-file? curr:square, queens:&:list:square -> result:bool [
local-scope
load-ingredients
curr-file:num <- get curr, file:offset
@ -62,7 +62,7 @@ def conflicting-file? curr:square, queens:&:list:square -> result:boolean [
break-unless queens
q:square <- first queens
qfile:num <- get q, file:offset
file-match?:boolean <- equal curr-file, qfile
file-match?:bool <- equal curr-file, qfile
reply-if file-match?, 1/conflict-found
queens <- rest queens
loop
@ -70,7 +70,7 @@ def conflicting-file? curr:square, queens:&:list:square -> result:boolean [
reply 0/no-conflict-found
]
def conflicting-diagonal? curr:square, queens:&:list:square -> result:boolean [
def conflicting-diagonal? curr:square, queens:&:list:square -> result:bool [
local-scope
load-ingredients
curr-rank:num <- get curr, rank:offset
@ -84,7 +84,7 @@ def conflicting-diagonal? curr:square, queens:&:list:square -> result:boolean [
file-delta:num <- subtract qfile, curr-file
rank-delta <- abs rank-delta
file-delta <- abs file-delta
diagonal-match?:boolean <- equal rank-delta, file-delta
diagonal-match?:bool <- equal rank-delta, file-delta
reply-if diagonal-match?, 1/conflict-found
queens <- rest queens
loop

View File

@ -7,7 +7,7 @@ def main [
local-scope
f:num/file <- $open-file-for-reading [/tmp/mu-x]
$print [file to read from: ], f, 10/newline
c:char, eof?:boolean <- $read-from-file f
c:char, eof?:bool <- $read-from-file f
$print [copying ], c, 10/newline
f <- $close-file f
$print [file after closing: ], f, 10/newline

View File

@ -17,7 +17,7 @@ def factorial n:num -> result:num [
after <base-case> [
# if n=0 return 1
zero?:boolean <- equal n, 0
zero?:bool <- equal n, 0
break-unless zero?
return 1
]