Compare commits
No commits in common. "de8f5c7cf4eb1f93f72d9315147d3c1a6f268a48" and "2e7db1b96983b28e4af56e3ab5bad875eb6407fa" have entirely different histories.
de8f5c7cf4
...
2e7db1b969
29
prelude.ld
29
prelude.ld
|
@ -339,29 +339,6 @@ fn join {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn split {
|
|
||||||
"Takes a string, and turns it into a list of strings, breaking on the separator."
|
|
||||||
(str as :string, break as :string) -> base :split (break, str)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn trim {
|
|
||||||
"Trims whitespace from a string. Takes an optional argument, `:left` or `:right`, to trim only on the left or right."
|
|
||||||
(str as :string) -> base :trim (str)
|
|
||||||
(str as :string, :left) -> base :triml (str)
|
|
||||||
(str as :string, :right) -> base :trimr (str)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn upcase {
|
|
||||||
"Takes a string and returns it in all uppercase. Works only for ascii characters."
|
|
||||||
(str as :string) -> base :upcase (str)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn downcase {
|
|
||||||
"Takes a string and returns it in all lowercase. Works only for ascii characters."
|
|
||||||
(str as :string) -> base :downcase (str)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
& in another prelude, with a better actual base language than Java (thanks, Rich), counting strings would be reasonable but complex: count/bytes, count/points, count/glyphs. Java's UTF16 strings make this unweildy.
|
& in another prelude, with a better actual base language than Java (thanks, Rich), counting strings would be reasonable but complex: count/bytes, count/points, count/glyphs. Java's UTF16 strings make this unweildy.
|
||||||
|
|
||||||
& TODO: add trim, trim/left, trim/right; pad/left, pad/right
|
& TODO: add trim, trim/left, trim/right; pad/left, pad/right
|
||||||
|
@ -641,8 +618,6 @@ fn slice {
|
||||||
base :into ([], slice)
|
base :into ([], slice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(str as :string, end as :number) -> base :str_slice (str, 0, end)
|
|
||||||
(str as :string, start as :number, end as :number) -> base :str_slice (str, start, end)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&&& keywords: funny names
|
&&& keywords: funny names
|
||||||
|
@ -1351,7 +1326,6 @@ pkg Prelude {
|
||||||
div/0
|
div/0
|
||||||
div/safe
|
div/safe
|
||||||
doc!
|
doc!
|
||||||
downcase
|
|
||||||
each!
|
each!
|
||||||
empty?
|
empty?
|
||||||
eq?
|
eq?
|
||||||
|
@ -1439,7 +1413,6 @@ pkg Prelude {
|
||||||
slice
|
slice
|
||||||
some
|
some
|
||||||
some?
|
some?
|
||||||
split
|
|
||||||
square
|
square
|
||||||
store!
|
store!
|
||||||
string
|
string
|
||||||
|
@ -1448,7 +1421,6 @@ pkg Prelude {
|
||||||
sum_of_squares
|
sum_of_squares
|
||||||
tan
|
tan
|
||||||
tau
|
tau
|
||||||
trim
|
|
||||||
tuple?
|
tuple?
|
||||||
turn/deg
|
turn/deg
|
||||||
turn/rad
|
turn/rad
|
||||||
|
@ -1459,7 +1431,6 @@ pkg Prelude {
|
||||||
unbox
|
unbox
|
||||||
unwrap!
|
unwrap!
|
||||||
unwrap_or
|
unwrap_or
|
||||||
upcase
|
|
||||||
update
|
update
|
||||||
update!
|
update!
|
||||||
values
|
values
|
||||||
|
|
114
sandbox.ld
114
sandbox.ld
|
@ -1,114 +0,0 @@
|
||||||
let input = "I remember my mother"
|
|
||||||
|
|
||||||
print! ("DOCTOR")
|
|
||||||
|
|
||||||
print! ("> ", input)
|
|
||||||
|
|
||||||
let sanitized = do input > trim > downcase
|
|
||||||
|
|
||||||
& ensuring we have spaces at the beginning and end
|
|
||||||
& this lets us match patterns as written below
|
|
||||||
let padded = join ([" ", sanitized, " "])
|
|
||||||
|
|
||||||
fn switch_persons {
|
|
||||||
("i") -> "you"
|
|
||||||
("you") -> "i"
|
|
||||||
("am") -> "are"
|
|
||||||
("me") -> "you"
|
|
||||||
("my") -> "your"
|
|
||||||
(x) -> x
|
|
||||||
}
|
|
||||||
|
|
||||||
fn repersonalize (x) -> do x >
|
|
||||||
trim >
|
|
||||||
split (_, " ") >
|
|
||||||
map (switch_persons, _) >
|
|
||||||
join (_, " ")
|
|
||||||
|
|
||||||
let output = match padded with {
|
|
||||||
"{x} hello {y}" -> "How do you do. Please state your problem"
|
|
||||||
"{x} hi {y}" -> "How do you do. Please state your problem"
|
|
||||||
"{x} computer {y}" -> random ([
|
|
||||||
"Do computers worry you"
|
|
||||||
"What do you think about machines"
|
|
||||||
"Why do you mention computers"
|
|
||||||
"What do you think machines have to do with your problem"
|
|
||||||
])
|
|
||||||
"{x} name {y}" -> "I am not interested in names"
|
|
||||||
"{x} sorry {y}" -> random ([
|
|
||||||
"Please don't apologize"
|
|
||||||
"Apologies are not necessary"
|
|
||||||
"What feelings do you have when you apologize"
|
|
||||||
])
|
|
||||||
"{x} i remember {y}" -> {
|
|
||||||
let switched = repersonalize (y)
|
|
||||||
random ([
|
|
||||||
"Do you often think of {switched}"
|
|
||||||
"Does thinking of {switched} bring anything else to mind"
|
|
||||||
"What else do you remember"
|
|
||||||
"Why do you recall {switched} right now"
|
|
||||||
"What in the present situation reminds you of {switched}"
|
|
||||||
"What is the connection between me and {switched}"
|
|
||||||
])
|
|
||||||
}
|
|
||||||
"{x} do you remember {y}" -> {
|
|
||||||
let switched = repersonalize (y)
|
|
||||||
random ([
|
|
||||||
"Did you think I would forget {switched}"
|
|
||||||
"Why do you think I should recall {switched} now"
|
|
||||||
"What about {switched}"
|
|
||||||
"You mentioned {switched}"
|
|
||||||
])
|
|
||||||
}
|
|
||||||
"{x} if {y}" -> {
|
|
||||||
let switched = repersonalize (y)
|
|
||||||
random ([
|
|
||||||
"Do you reall think that its likely that {switched}"
|
|
||||||
"Do you wish that {switched}"
|
|
||||||
"What do you think about {switched}"
|
|
||||||
"Really--if {switched}"
|
|
||||||
])
|
|
||||||
}
|
|
||||||
"{x} i dreamt {y}" -> {
|
|
||||||
let switched = repersonlize (y)
|
|
||||||
random ([
|
|
||||||
"Really--{y}"
|
|
||||||
"Have you ever fantasized {y} while you were awake"
|
|
||||||
"Have you dreamt {y} before"
|
|
||||||
])
|
|
||||||
}
|
|
||||||
"{x} dream about {y}" -> {
|
|
||||||
let switched = repersonalize (y)
|
|
||||||
"How do you feel about {switched} in reality"
|
|
||||||
}
|
|
||||||
"{x} dream {y}" -> random ([
|
|
||||||
"What does this dream suggest to you"
|
|
||||||
"Do you dream often"
|
|
||||||
"What persons appear in your dreams"
|
|
||||||
"Don't you believe that dream has to do with your problem"
|
|
||||||
])
|
|
||||||
"{x} my mother {y}" -> {
|
|
||||||
let switched = repersonalize (y)
|
|
||||||
random ([
|
|
||||||
"Who else in your family {y}"
|
|
||||||
"Tell me more about your family"
|
|
||||||
])
|
|
||||||
}
|
|
||||||
"{x} my father {y}" -> random ([
|
|
||||||
"Your father"
|
|
||||||
"Does he influence you strongly"
|
|
||||||
"What else comes to mind when you think of your father"
|
|
||||||
])
|
|
||||||
_ -> random ([
|
|
||||||
"Very interesting"
|
|
||||||
"I am not sure I understand you fully"
|
|
||||||
"What does that suggest to you"
|
|
||||||
"Please continue"
|
|
||||||
"Go on"
|
|
||||||
"Do you feel strongly about discussing such things"
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
print! (">>> ", upcase (output))
|
|
||||||
|
|
||||||
|
|
|
@ -281,13 +281,6 @@
|
||||||
"range" range
|
"range" range
|
||||||
"unbox" unbox
|
"unbox" unbox
|
||||||
"store!" store!
|
"store!" store!
|
||||||
"split" string/split
|
|
||||||
"upcase" string/ascii-upper
|
|
||||||
"downcase" string/ascii-lower
|
|
||||||
"trim" string/trim
|
|
||||||
"trimr" string/trimr
|
|
||||||
"triml" string/triml
|
|
||||||
"str_slice" string/slice
|
|
||||||
})
|
})
|
||||||
|
|
||||||
(def base (let [b @{}]
|
(def base (let [b @{}]
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
# (set (out :errors) (validated :errors))
|
# (set (out :errors) (validated :errors))
|
||||||
(each err (validated :errors)
|
(each err (validated :errors)
|
||||||
(e/validation-error err))
|
(e/validation-error err))
|
||||||
(break (-> out j/encode string)))
|
(break out))
|
||||||
(setdyn :out console)
|
(setdyn :out console)
|
||||||
(try
|
(try
|
||||||
(set result (i/interpret (parsed :ast) ctx))
|
(set result (i/interpret (parsed :ast) ctx))
|
||||||
|
@ -55,13 +55,6 @@
|
||||||
|
|
||||||
# (comment
|
# (comment
|
||||||
(do
|
(do
|
||||||
(def source `let foo = foo bar baz`)
|
(-> (ludus `
|
||||||
(def out (-> source
|
doc! (mod)
|
||||||
ludus
|
`)))
|
||||||
j/decode))
|
|
||||||
(def console (out "console"))
|
|
||||||
(print console)
|
|
||||||
(def result (out "result"))
|
|
||||||
(print result)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user