Why comma is special?

Notices and updates
Locked
Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Why comma is special?

Post by Kazimir Majorinc »

I noted that comma cannot be part of the symbol; it appears identifier

x,y

is understood like it is the sequence of three symbols

x , y

Is it intentional?

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

Yes, it is intentional. The comma is a newlisp idiom for establishing local variables in a function:

Code: Select all

(define (foo param , a b c)
  ;; here, a, b, and c are nil
  (println "Hello world"))
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

DrDave
Posts: 126
Joined: Wed May 21, 2008 2:47 pm

Post by DrDave »

From the manual
Some of the example programs contain functions that use a comma to separate the parameters into two groups. This is not a special syntax of newLISP, but rather a visual trick. The comma is a symbol just like any other symbol.
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.
"Getting Started with Erlang" version 5.6.2

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

It is a symbol and may be set, but the comma is recognized individually by the parser and is not a valid character in other symbols.
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Locked