setq vs. = vs. arrays

D

danmc

Guest
(declare x[5])
(setq x[3] 7.2)

fails with *Error* setq: argument #1 should be a symbol (type template
= "sg") - x[3]

declare( x[5] )
x[3] = 7.2

works.

The manual says

"Sets a variable to a new value. setq is the same as the assignment (=)
operator. This is a syntax form."

So I'm puzzled. If I have a somewhat large program that is written
using skill style (foo x) instead of procedural style foo(x), how can I
assign an element in an array?

Thanks
-Dan
 
Hi Dan, this is a trick of the SKILL parser. x[3]=7.2 does not
parse as setq something while x=7.2 does.

To find out how the parser reads infix notation into an sexpression,
do the following.

(sstatus printinfix nil)
'(x[3] = 7.2)


this will output the expression in prefix notation. You'll see
that it is not a call to setq at all but rather a call to setarray.

setq is only able to set the value of a symbol, not of an array
element.

If you simply want to assign to an array element, you can also simply
use x[3] = 7.2
this works as well inside a program that it written with prefix
notation.
SKILL does not care if your program is written with infix or prefix or
a mixture of the two.


after (sstatus printinfix nil) you can even pp a function to see the
entire
function in infix notation. or you can (sstatus printinfix t) and pp
the function
to see it with infix notation.

hope this helps.

-jim

danmc wrote:
)
(setq x[3] 7.2)

fails with *Error* setq: argument #1 should be a symbol (type template
= "sg") - x[3]

declare( x[5] )
x[3] = 7.2

works.

The manual says

"Sets a variable to a new value. setq is the same as the assignment (=)
operator. This is a syntax form."

So I'm puzzled. If I have a somewhat large program that is written
using skill style (foo x) instead of procedural style foo(x), how can I
assign an element in an array?

Thanks
-Dan
 
Jimka wrote:
=7.2 does not
parse as setq something while x=7.2 does.

To find out how the parser reads infix notation into an sexpression,
do the following.

(sstatus printinfix nil)
'(x[3] = 7.2)

hope this helps.

-jim
yes. Big help!

Thank you.

-Dan
 

Welcome to EDABoard.com

Sponsor

Back
Top