From 1afd0cdc7820d9c3a9ae032ea40545d7d32bf9bf Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Tue, 5 Jan 2021 22:16:50 +0300 Subject: String type added. --- examples/generated.csx | 100 +++++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 40 deletions(-) (limited to 'examples/generated.csx') diff --git a/examples/generated.csx b/examples/generated.csx index 14943b2..62fd2eb 100644 --- a/examples/generated.csx +++ b/examples/generated.csx @@ -1,47 +1,67 @@ +{ Base Utilities } + [set no [fn [x] [same x []]]] -[set outint [fn [n] [if [< n 0] - [do [out 45] [outint [neg n]]] - [if [< n 10] - [out [+ 48 n]] - [do - [outint [div n 10]] - [out [+ 48 [mod n 10]]] +[set id [fn [arg] arg]] +[set list [fn args args]] + +[set catrev [fn [a b] [if a [catrev [tail a] [pair [head a] b]] b]]] +[set rev [fn [l] [catrev l []]]] +[set cat [fn [a b] [catrev [rev a] b]]] + +[set map [fn [f l] [if l [pair [f [head l]] [map f [tail l]]]]]] +[set reduce [fn [f l] [if [no l] [] [if [no [tail l]] [head l] + [f [head l] [reduce f [tail l]]] +]]]] + +[set - [fn =[a rest] [+ a [reduce + [map neg rest]]]]] + + +{ Input-Output } + +[set newline [str [list 10]]] + +[set outint [fn [n] + [set zero 48] + [set minus 45] + [if [< n 0] + [do [out minus] [outint [neg n]]] + [if [< n 10] + [out [+ zero n]] + [do + [outint [div n 10]] + [out [+ zero [mod n 10]]] + ] ] ] -]]] -[set map [fn [f l] [if l [pair [f [head l]] [map f [tail l]]]]]] -[set id [fn args args]] -[set outstr [fn [str] [if str [do [out [head str]] [outstr [tail str]]]]]] -[set newline [fn [] [out 10]]] -[set instr [fn [] - [set c [in]] - [if [no [same c 10]] [pair c [instr]]] ]] -[set outints [fn [l] - [set outcontent [fn [l] - [if l [do [outint [head l]] [out 32] [outcontent [tail l]]]] + +[set outstr [fn [str] + [set outstrat [fn [str i len] [if [no [same i len]] [do + [out [str i]] + [outstrat str [+ i 1] len] + ]]]] + [outstrat str 0 [len str]] +]] + +[set output [fn objs [map [fn [obj] [if + [same [type obj] 'int] [outint obj] + [same [type obj] 'str] [outstr obj] +]] objs]]] + +[set instr [fn [] + [set instract [fn [] + [set c [in]] + [if [no [same c 10]] [pair c [instract]]] ]] - [out 91] [outcontent l] [out 93] + [str [instract]] ]] -[set rappend [fn [a b] [if a [rappend [tail a] [pair [head a] b]] b]]] -[set rev [fn [l] [rappend l []]]] -[set append [fn [a b] [rappend [rev a] b]]] -[set backwards [sx body [pair 'do [rev body]]]] - -[outstr "-= loaded =-"] -[newline] -[outstr "Hello, I am Casey Shawn Exton. What is your name?"] -[newline] -[outstr "> "] + + +{ The Program } + +[output "Hello, I am Casey Shawn Exton. " "What is your name?" newline] +[output "> "] [set name [instr]] -[outstr "Nice to meet you, "] -[outstr name] -[outstr "."] -[newline] -[outstr "I have to go. Goodbye!"] -[newline] - -[backwards - [outstr magic] - [set magic [rev "magic"]] -] +[output "Nice to meet you, " name "." newline] +[output "Your name is " [len name] " characters long." newline] +[output "I have to go. Goodbye!" newline] -- cgit v1.2.3