Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Newbie question: [ ] vs. ( )

0 views
Skip to first unread message

Patrick King

unread,
Apr 8, 2005, 7:08:02 PM4/8/05
to
It seems to me there is no real difference between brackets and
parentheses in Scheme. Is there some convention that governs when to use
which?

Pat

Abdulaziz Ghuloum

unread,
Apr 8, 2005, 7:30:59 PM4/8/05
to
Patrick King wrote:

Not every implementation supports the square brackets. Parentheses are
standard.

If you still want to use square brackets, the places where they're used
commonly is where many nested parens hinder readability:

(let-values ([(x y) (foo baz)]
[(t q r) (values 1 2 3)])
...)

(letrec ([id (lambda (x) x)]
[f
(lambda (x)
(id f))])
...)

and so on. Or to group clauses:

(cond
[test expr]
[(pred? x) foo]
[else ...])

(case foo
[(a b c) 'a-or-b-or-c]
[else 'neither])

(syntax-rules ()
[(_ x) (foo x)]
[(_ x y) (bar x)])

(case-lambda ; if your system has it
[(x y) (cons x y)]
[(x y z) (vector x y z)]
[rest rest])


Aziz,,,

Matthias Buelow

unread,
Apr 9, 2005, 5:54:42 AM4/9/05
to
Abdulaziz Ghuloum <aghu...@c-s-remove-dashes.indiana.edu> writes:

> If you still want to use square brackets, the places where they're
> used commonly is where many nested parens hinder readability:

That's highly subjective, though. I find Scheme source interspersed
with [] much harder to read than without.

mkb.

Hans Oesterholt-Dijkema

unread,
Apr 9, 2005, 10:50:24 AM4/9/05
to
Patrick King schreef:

Not at all. Standard is '(' and ')'. Other parentheses are added
to improve readability. However I personally have a harder time
reading sources with multiple types of parentheses.

--
Hans

0 new messages