Sometimes I think OOP code can be easier to read than functional or procedural
[1..10].map(x => x * 2).forEach(print)
versus
forEach(map([1..10], x => x * 2)), print)
is it possible for a language to allow you to write in both ways? I think F# has something like it.
>>5
I do wrote some initializing code. But it is in constant redesign for the last few years.
// std1 stage defines macro utility `form` which allows hygienic macros
use lib.std0
find Xs F => if Xs end then No
else if F Xs.head then Xs.head
else find Xs.tail F
printable? X => if tag_of.X isnt fn then Yes
else if Yes is X then Yes
else if No is X then Yes
else if Void is X then Yes
else if #mutate is X then Yes
else if #head is X then Yes
else find exports_of X: E => E.0 is print
print X => if printable? X then X print
else [`#[` address_of.X.print `]`] join_text
// intersperse Xs with M
// infix 'and' [cat dog fox] --> [cat and dog and fox]
infix M Xs => if Xs end then []
else | T = Xs tail
| if T end then Xs
else ((infix M T) headed M) headed Xs.head
say @Xs => | Xs = infix ' ': Xs map: X => if tag_of.X is text then X else print X
| text_out [@Xs '\n'].join_text
bad @What => | say bad @What | halt
variable_name? X => X of text and X.size > 0 and if X.0 upcase? then Yes else X is '?'
function_name? X => X of text and not X^variable_name?
quasiquote X Head =>
if variable_name? X then X
else if Head and function_name? X then list (list _ q X) wrapped (list '&' X)
else if not: X of list then
if X is '@' then X else list _ q X
else if X.size is 0 then list _ q X
else if X.0 is '$' then X.1
else if X.0 is form then bad nested form X.print
else if X.0 is _ and X.size > 1 then //special forms cant be redefined
with @X: A B @Xs => list list A B @(Xs map: X => quasiquote X No)
else list list (quasiquote X.0 Yes) @(X.tail map: X => quasiquote X No)
form Gs X =>
if Gs.size > 0
then list _ let (Gs map: G => if G of list and G.size > 0 and G.0 is `\\`
then list G.1 G
else list G (list (list _ q G) gensym))
(quasiquote X No)
else quasiquote X No
DefaultLabel = '[DefaultLabel]'
normLabel L => if L of text then L
else if L end then DefaultLabel // is this the Right Thing?
else L 0
block Label Body => list _ block normLabel.Label Body
continue Label => list _ continue normLabel.Label
break Label @Value => list _ break normLabel.Label
(if Value end then Void else Value 0)
export @lib.std0 //re-export whole package
'form'
printable? print say bad infix
function_name? variable_name?
'block' 'continue' 'break'