When if is just a function
ryelang.org
When if is just a function
1–10 of 111 posts
Re: When if is just a function
#2Seems lispy
Re: When if is just a function
#3Combinatory programing offers functional control flow. (Here is a straight forward explanation: https://blog.zdsmith.com/series/combinatory-programming.html ) I was inspired to write `better-cond` in Janet:
(defn better-cond
[& pairs]
(fn [& arg]
(label result
(defn argy [f] (if (> (length arg) 0) (f ;arg) (f arg))) # naming is hard
(each [pred body] (partition 2 pairs)
(when (argy pred)
(return result (if (function? body)
(argy body) # calls body on args
body)))))))
Most Lisps have `cond` like this:
(def x 5)
(cond
((odd? x) "odd") ; note wrapping around each test-result pair
((even? x) "even"))
Clojure (and children Fennel and Janet) don't require wrapping the pairs:
(def x 5)
(cond
(odd? x) "odd"
(even? x) "even")
My combinatoresque `better-cond` doesn't require a variable at all and is simply a function call which you can `map` over etc.:
((better-cond
(fn [x] (> 3 x)) "not a number" # just showing that it can accept other structures
odd? "odd"
even? "even") 5)
Of course, it can work over multiple variables too and have cool function output:
(defn recombine # 3 train in APL or ϕ combinator
[f g h]
(fn (& x) (f (g ;x) (h ;x))))
(((better-cond
|(function? (constant ;$&))
|($ array + -)) recombine) 1 2) # |( ) is Janet's short function syntax with $ as varsRe: When if is just a function
#4Seems lispy
Without the discussion of applicative-order versus normal-order.
Re: When if is just a function
#5Seems lispy
BTW: In Lisps, if is still a special form / macro, because in Lisp lists are evaluated by default, in Rebols if can be a function because blocks (lists) aren't evaluated by default.
Re: When if is just a function
#6Seems lispy
I checked the Rye homepage, and it has "dialects" which allow more familiar math infix notation. In that sense it is very tcl-y, tcl technically being a lisp.
Looking at their rather confusing looping mechanisms, they probably could benefit from being a little more tcl-y, since tcl has some of the best looping semantics I've worked with.
Re: When if is just a function
#7Is this just a quirk in my display, or are all the code blocks in this formatted like a CIA black highlighter
Re: When if is just a function
#8Smalltalk, anyone? I guess the OO version.
Re: When if is just a function
#9Seems lispy
I checked the Rye homepage, and it has "dialects" which allow more familiar math infix notation. In that sense it is very tcl-y, tcl technically being a lisp. Looking at their rather confusing looping mechanisms, they probably could benefit from being a little more tcl-y, since tcl has some of the best looping semantics I've worked with.
Any concrete feedback on looping mechanisms being confusing is appreciated.
Re: When if is just a function
#10Is this just a quirk in my display, or are all the code blocks in this formatted like a CIA black highlighter
I checked in Firefox and Chrome (on Linux) and code samples look OK to me. What browser/OS are you using. Maybe send me a screenshot at janko dot itm at gmail.