append demands a string

Q&A's, tips, howto's
Locked
kanen
Posts: 145
Joined: Thu Mar 25, 2010 6:24 pm
Contact:

append demands a string

Post by kanen »

Most of newLISP is forgiving, not so with append.

Code: Select all

newLISP v.10.2.4 on Linux IPv4 UTF-8, execute 'newlisp -h' for more info.

> (set 'foo 4)
4
> (println "foo is: " foo)
foo is: 4
4
> (println (append "foo is: " foo))

ERR: string expected in function append : foo
> (println (append "foo is: " (string foo)))
foo is: 4
"foo is: 4"
> 
> 
I consider this behavior to be inconsistent with the rest of newLISP's variable handling. Is it just me?
. Kanen Flowers http://kanen.me .

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

Re: append demands a string

Post by Kazimir Majorinc »

One specificity of Newlisp is that it has + and add, two different operators for two types of data, with automatic conversion if argument does not match type determined by function call.

Sometimes, Newlisp doesn't convert automatically. For example (sym '(1 2)) returns error. (sym (string '(1 2))) works.

In append, type of the result is determined by first argument, with error if other arguments do not match the first one.

It appears that you suggest fourth approach, i.e. automatic conversion of other arguments to the first argument.

I'm more in favour of the fifth approach "don't do smart things behind my back". That means, default should be as it is now, and if one wants automatic conversion, there should be built-in or user defined function append-with-conversion which does that. As far as I know, Lutz doesn't apply that philosophy at all.

I guess it is up to Lutz to make strategic decision and gradually move toward consistency in that direction. But I think that, yes, your proposal is close to some general, forgiving spirit of the language.

Locked