~technomancy/fennel

1

parens instead of brackets for destructuring?

Details
Message ID
<8fffbddc-7af8-478e-bc94-54c93cedab1a@www.fastmail.com>
DKIM signature
fail
Download raw message
DKIM signature: fail
In [the tutorial section on error handling](https://fennel-lang.org/tutorial#error-handling) it says,

"You can interact with this style of function in Fennel by destructuring with parens instead of square brackets"

    (let [(f msg) (io.open "file" "rb")]  ; snip

Why would you do that instead of using square brackets around "f msg"? Using parens makes it look like a function call, no?
Details
Message ID
<87a6zfaef5.fsf@hagelb.org>
In-Reply-To
<8fffbddc-7af8-478e-bc94-54c93cedab1a@www.fastmail.com> (view parent)
DKIM signature
missing
Download raw message
John Gabriele <jgabriele@fastmail.fm> writes:

> "You can interact with this style of function in Fennel by
> destructuring with parens instead of square brackets"
>
>     (let [(f msg) (io.open "file" "rb")]  ; snip
>
> Why would you do that instead of using square brackets around "f msg"?
> Using parens makes it look like a function call, no?

That's a great question--the use of parens does have that downside of
making it look like a function call. The reason we can't use [] or {} is
that those already have a distinct meaning in this context.

    (fn numbers [] [1 2 3])

    (let [[one two three] (numbers)]
      (print (+ one two three)))

Square brackets are used to destructure actual tables, which are
distinct from multiple return values, which are ... somewhat table-like
in some ways but not really first-class values. So because the []
notation is already taken, (and {} is taken for destructuring against
key/value non-sequential tables) the only matching delimiters left for
us to use are parens, and we use them for destructuring and pattern
matching against multiple values.

-Phil
Export thread (mbox)