Re: (NIL) vs Nothing

2017-01-29 Thread dean
Hi Chrostophe and Alex

Thank you very much for your adviceIt is very timely.

I'm only too aware of the dangers of using setq, having been bitten a few
times now by interference between functions in my whole program.

I'm tending to develop functions in isolation so I can watch them like a
hawk. setq isn't a problem in such isolation and the ONLY reason I'm  using
setq is my lack of adeptness reconciling the the scoping inherent in "let"
with the bracketing I THINK I need to obtain the desired flow of control
i.e.

(let Some_sym...
  Some_sym is seen anywhere up to the closing bracket above  ---)

but then I seem to want to access Some_sym beyond the closing bracket
SEEMINGLY dictated by the flow of control.

Having just sorted out my first object's logic and layout now is probably a
good time to go back and replace all of my setq's with let's. If either of
you have any advice on how best to use "let"...I'd certainly welcome it
i.e. is it just a case of

(let A 1 B2


write your program as usual here safe in the knowledge that you have access
to A and B


)

I tried this but don't seem to get B

: (let A 1 B 2
(prinl A)
(prinl B)
)
1


I would like to crack this so any advice re how to correctly use "let"
would be very welcome and appreciated. BTWPL's object system is a
pleasure to use. Thank you for it!

Best Regards
Dean








On 28 January 2017 at 19:13, Alexander Burger  wrote:

> Hi Christophe,
>
> > > (de fltr (Buf Ln)
> > >(setq New_buf (mapcar '((Ele) (pack (tail (- (length Ln)) (chop
> Ele
> > >   (filter '((Ele) (pre? Ln Ele)) Buf
> >
> > I'm not an expert, I just want to warn and maybe be confirmed.
> > As Alex said recently, PicoLisp programs should rarely use setq.
>
> Indeed! When I saw the above definition, I was ready to say something
> about it.
> But then I understood that Dean obviously just extracted a sample from some
> other code he is working on, and that the 'setq' might be the remains of
> experimentation.
>
>
> > I'd add (please confirm):
> > 1) especially in function definitions, as
> > 2) it creates/modifies like «global variables», which many consider
> > bad practice.
>
> Yes. At least - if it is really necessary - is should be named '*New_buf'
> to
> mark it clearly as a global.
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: (NIL) vs Nothing

2017-01-29 Thread dean
Hi Alex
Thank you for the adviceI've just this minute used debug by
coincidence...but not with breakpoint and I've never used trace.
so thank you for those and also for putting me straight re the positioning
and syntax of (let (A 1 B 2..
Please have a good rest of the weekend.
Best Regards
Dean

On 29 January 2017 at 14:42, Alexander Burger  wrote:

> Hi Dean,
>
> > I'm tending to develop functions in isolation so I can watch them like a
> > hawk.
>
> Watching like a hawk is always good! ;)
>
> In addition to that, I would recommend to use 'trace' and 'debug'.
> Especially
> 'trace' is more useful than it may seem, letting you monitor your whole
> program's behavior selectively. Individual functions can be single-stepped
> with
> 'debug', or by manually setting a breakpoint '!' with 'edit' or in the
> source
> code.
>
>
> > (let Some_sym...
> >   Some_sym is seen anywhere up to the closing bracket above  ---)
> >
> > but then I seem to want to access Some_sym beyond the closing bracket
> > SEEMINGLY dictated by the flow of control.
>
> Just move '(let Some_sym ...' up.
>
>
> > (let A 1 B2
> >
> > write your program as usual here safe in the knowledge that you have
> access
> > to A and B
>
> I think you mean
>
>(let (A 1  B 2)
>   ... )
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: (NIL) vs Nothing

2017-01-29 Thread dean
I've just tried sprinkling (!) in my source.
That is going to help me A LOT. It looks like the PL equivalent of int 3 :)


Re: a bunch of questions about syntax

2017-01-29 Thread Alexander Burger
On Sat, Jan 28, 2017 at 09:55:14PM +0100, pd wrote:
> Thank you Alex for your patience, I see I have a severe confussion about
> how picolisp manages lists

No problem! It is good to discuss this here, as it may help others too.


> let's start by the begining... as far as I know   (f a b 4)  is just a list
> equivalent to (f . (a . (b . (4 . NIL  and the fact being also a
> function call to function f applying parameters a b 4 is just a matter of
> "convention", simply when picolisp evals a list with a first item not being
> a number it supposes it's a function call and tries to evaluate first item
> (it doesn't matter if first item is a symbol or another list, it gets
> evaluated) which is supposed to be evaluated to a function value

That's right.


> With this point of view I understand what you mean when saying  (f 1 a b c)
> is just the same as (f 1 . (a b c)) and thus you can view a, b, c as a list

Yes.


> so you can describe this funcion as (f num . 'lst), ok, but also I think
> ...
> you could describe the function f also as (f . 'lst) . The only difference

Yes, but without the quotes. As a function reference (f num . 'lst) is
impossible, as the quote indicates evaluation which is not handled by PicoLisp
this way.


> But if you describe a function like (g num 'lst) is a quite different thing
> because you are expecting two arguments the first one being a number and
> the second being a list (of unlimited number of items), really all

Yes.


> functions described have an unlimited number of arguments but function g
> packs all arguments but the first in a list.

No. This is not done by 'g'. This function *expects* a list after evaluating its
second argument.


> >(if (testSomething) (doSomething1) (doSomething2) (doSomething3))
> ...
> but this also means the only way to indicate several executable expressions
> in the "then-clause" is to surround them between parens, i.e.  (if (= 2 2)
> ((print "equal") (print "2")) (print "not equal") (print "not 2"))   I

No. This gives a crash (try it, and think about why ;).

The "then" clause must be a single expression. Typicaley you use 'prog'
if you need to call more than one expression here.


> appreciate here an absence of symmetry, you must pack all exe expressions

That's right.


> why not to define and describe function if in a symmetrical way as   (if
> 'any prg1 prg2)  even when not obeying parens economy?   (sure there is a
> good reason to do it that way simply I'm not able to see)

If 'if' were specified this way, it would lose its simplicity because you always
need additional nesting for the "then" clause.

For more complex conditional expressions, we use 'cond' instead of 'if'.


> - two functions f described this way:
> 
>(f num . lst)
>(f num1 num2)
> 
> then the list (f 1 2) is a valid call for both functions, the first f will
> bind first parameter to numer 1 and second parameter to list (2) (all
> remaining parameters as a list) while the second f will bind 1 to num1 and
> 2 to num2 (descarding empty list NIL).

Correct.

> My confusion here is picolisp must
> do two pops to bind parameters for a first f function call but three pops
> to bind parameters for a second f function call. How discriminate picolisp
> between each cases? I suppose the answer is function definition:
> 
> first f defined as (de f (X . Rest) (...) )
> second f defined as (de f (X Y) (...) )

Exactly. The interpreter finds either (X . Rest) or (X Y) when evaluating (f 1 
2),
so it knows what to do.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (NIL) vs Nothing

2017-01-29 Thread Alexander Burger
Hi Dean,

> I'm tending to develop functions in isolation so I can watch them like a
> hawk.

Watching like a hawk is always good! ;)

In addition to that, I would recommend to use 'trace' and 'debug'. Especially
'trace' is more useful than it may seem, letting you monitor your whole
program's behavior selectively. Individual functions can be single-stepped with
'debug', or by manually setting a breakpoint '!' with 'edit' or in the source
code.


> (let Some_sym...
>   Some_sym is seen anywhere up to the closing bracket above  ---)
> 
> but then I seem to want to access Some_sym beyond the closing bracket
> SEEMINGLY dictated by the flow of control.

Just move '(let Some_sym ...' up.


> (let A 1 B2
> 
> write your program as usual here safe in the knowledge that you have access
> to A and B

I think you mean

   (let (A 1  B 2)
  ... )

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (NIL) vs Nothing

2017-01-29 Thread dean
If we take objects as an example...You might want to use these to create
static variables using object properties which you want to persist within a
limited scope. You might setq the object itself to make it persist but do
you manipulate the objects properties (that you want to persist) using setq
or let inside the object's methods. I'm sure the answer will become clear
after experimenting with let but I'm not sure at the moment.

On 29 January 2017 at 11:47, dean  wrote:

> Hi Chrostophe and Alex
>
> Thank you very much for your adviceIt is very timely.
>
> I'm only too aware of the dangers of using setq, having been bitten a few
> times now by interference between functions in my whole program.
>
> I'm tending to develop functions in isolation so I can watch them like a
> hawk. setq isn't a problem in such isolation and the ONLY reason I'm  using
> setq is my lack of adeptness reconciling the the scoping inherent in "let"
> with the bracketing I THINK I need to obtain the desired flow of control
> i.e.
>
> (let Some_sym...
>   Some_sym is seen anywhere up to the closing bracket above  ---)
>
> but then I seem to want to access Some_sym beyond the closing bracket
> SEEMINGLY dictated by the flow of control.
>
> Having just sorted out my first object's logic and layout now is probably
> a good time to go back and replace all of my setq's with let's. If either
> of you have any advice on how best to use "let"...I'd certainly welcome it
> i.e. is it just a case of
>
> (let A 1 B2
>
>
> write your program as usual here safe in the knowledge that you have
> access to A and B
>
>
> )
>
> I tried this but don't seem to get B
>
> : (let A 1 B 2
> (prinl A)
> (prinl B)
> )
> 1
>
>
> I would like to crack this so any advice re how to correctly use "let"
> would be very welcome and appreciated. BTWPL's object system is a
> pleasure to use. Thank you for it!
>
> Best Regards
> Dean
>
>
>
>
>
>
>
>
> On 28 January 2017 at 19:13, Alexander Burger  wrote:
>
>> Hi Christophe,
>>
>> > > (de fltr (Buf Ln)
>> > >(setq New_buf (mapcar '((Ele) (pack (tail (- (length Ln)) (chop
>> Ele
>> > >   (filter '((Ele) (pre? Ln Ele)) Buf
>> >
>> > I'm not an expert, I just want to warn and maybe be confirmed.
>> > As Alex said recently, PicoLisp programs should rarely use setq.
>>
>> Indeed! When I saw the above definition, I was ready to say something
>> about it.
>> But then I understood that Dean obviously just extracted a sample from
>> some
>> other code he is working on, and that the 'setq' might be the remains of
>> experimentation.
>>
>>
>> > I'd add (please confirm):
>> > 1) especially in function definitions, as
>> > 2) it creates/modifies like «global variables», which many consider
>> > bad practice.
>>
>> Yes. At least - if it is really necessary - is should be named '*New_buf'
>> to
>> mark it clearly as a global.
>>
>> ♪♫ Alex
>> --
>> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>>
>
>