Skip to content

Instantly share code, notes, and snippets.

@maximvl
Created August 6, 2016 17:18
Show Gist options
  • Save maximvl/640aa095ab13792d21032a9e171c77bd to your computer and use it in GitHub Desktop.
Save maximvl/640aa095ab13792d21032a9e171c77bd to your computer and use it in GitHub Desktop.
@steveGit's version of LC in Red
Red []
lc: function [rule] [
parse rule [
some [
s: word! 'in skip
(in: last reduce/into ['foreach s/1 s/3 make block! 4] in)
| 'if skip
(in: last reduce/into ['if to-paren s/2 make block! 4] in)
| skip '|
(res: s/1 fun: in: make block! 4)
| (reduce/into ['reduce/into res 'tail 'out] in) break
]
]
has [out] compose [out: make block! 10 (fun) out]
]
x-set: [1 2 3]
r: lc [[x + y ] | x in x-set y in [10 100 1000] if [ x <> 2]]
print source r
print r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment