Re: Method undefined - why?

2017-03-24 Thread Alexander Burger
Hi Thorsten,

> (class 1 ...)
> (dm ...)
> (dm ...)
> 
> (class 2 ...)
> (dm ...)
> (dm ...)
> 
> The reader seems to remember which class was defined last, and
> associates the following methods to that class.

Not the reader, but the 'class' function:

   (de class Lst
  (let L (val (setq *Class (car Lst)))
 (def *Class
...

It remembers that class in the '*Class' global.

So the 'class' function is not absolutely necessary.


> Would you rather write the classical definitions to a file and then load
> that?

No, it is perfectly legal to build the class structures manually as you did. The
class definition in your first mail was correct.

What was missing was only the definition for methods like 'hi>'. Without them,
'hi>' is just a symbol with value 'NIL', so that calling it like

   : (hi> Obj)
   !? (hi> Obj)
   hi> -- Undefined
   ?

naturally gives an "Undefined" error. This has nothing to do with classes and
OOP. Instead, you could send the message to 'Obj' explicitly with

   (send 'hi> Obj)

or

   (try 'hi> Obj)


Defining with 'dm' just takes care to set the proper function definition for
the symbol 'hi>'. Instead, you could also do

   (setq hi> meth)

or perhaps better

   (def 'hi> meth)

Now also a call like (hi> Obj) works.

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


Re: Method undefined - why?

2017-03-23 Thread Thorsten Jolitz
Thorsten Jolitz 
writes:

> so somehow my understanding of read macros is false here:
>
> (class ~(any (pack '+ ClsNm)))

Grrr ... of course when reading (de foo (ClsNm) ...) ClsNm is still NIL,
so the outcome of the above is (class +) which can't work. Sorry for the
noise.

-- 
cheers,
Thorsten

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


Re: Method undefined - why?

2017-03-23 Thread Thorsten Jolitz
Thorsten Jolitz 
writes:

> Alexander Burger  writes:

Ok, this works ;-)

: (de foo2 (ClsNm MethNm) (class +Bar) (dm plus> (X) (+ 1 X)))
-> foo2
: (foo2)
-> plus>
: (setq B (new '(+Bar)))
-> $177641167640474
: (plus> B 3)
-> 4
'))

so somehow my understanding of read macros is false here:

(class ~(any (pack '+ ClsNm)))

> Hi Alex,
>
>>> : (de +Test
>>>(T (Hi) (=: hi Hi))
>>>(hi> (Nm) (or (text (: hi) Nm) "Dear Sir or Madam,")) )
>>> -> +Test
>>
>> .. while this is half of the lunch ...
>>
>>> : (hi> Foo "Alex")  
>>> !? (hi> Foo "Alex")
>>> hi> -- Undefined  # => WHY?
>>
>> .. it is better (as Joe Bogner suggested) to use 'dm'.
>>
>> The reason is that 'dm' does a little more: It also defines the symbol
>> 'hi>' to
>> behave as a sender of messages to objects, equivalent to
>>
>>: (setq hi> meth)
>>-> 22951574276
>>
>> With that, the following works
>>
>>: (hi> Foo "Thorsten")
>
> Ok, I see.
>
> But, in a source file it's obvious how to use (class) and (dm)
>
> (class 1 ...)
> (dm ...)
> (dm ...)
>
> (class 2 ...)
> (dm ...)
> (dm ...)
>
> The reader seems to remember which class was defined last, and
> associates the following methods to that class.
>
> How to use (class) and (dm) in a program is not that obvious for me:
>
> :(de foo (ClsNm MethNm) (class ~(any (pack '+ ClsNm))) (dm ~(any (pack
> MethNm ">") (X) (+ 1 X
> -> foo
> : (foo "Bar" "plus")
> !? (val (setq *Class (car Lst)))
> 270136 -- Variable expected
> '
>
> Would you rather write the classical definitions to a file and then load
> that?

-- 
cheers,
Thorsten

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


Re: Method undefined - why?

2017-03-23 Thread Thorsten Jolitz
Alexander Burger  writes:

Hi Alex,

>> : (de +Test
>>(T (Hi) (=: hi Hi))
>>(hi> (Nm) (or (text (: hi) Nm) "Dear Sir or Madam,")) )
>> -> +Test
>
> .. while this is half of the lunch ...
>
>> : (hi> Foo "Alex")  
>> !? (hi> Foo "Alex")
>> hi> -- Undefined  # => WHY?
>
> .. it is better (as Joe Bogner suggested) to use 'dm'.
>
> The reason is that 'dm' does a little more: It also defines the symbol
> 'hi>' to
> behave as a sender of messages to objects, equivalent to
>
>: (setq hi> meth)
>-> 22951574276
>
> With that, the following works
>
>: (hi> Foo "Thorsten")

Ok, I see.

But, in a source file it's obvious how to use (class) and (dm)

(class 1 ...)
(dm ...)
(dm ...)

(class 2 ...)
(dm ...)
(dm ...)

The reader seems to remember which class was defined last, and
associates the following methods to that class.

How to use (class) and (dm) in a program is not that obvious for me:

:(de foo (ClsNm MethNm) (class ~(any (pack '+ ClsNm))) (dm ~(any (pack
MethNm ">") (X) (+ 1 X
-> foo
: (foo "Bar" "plus")
!? (val (setq *Class (car Lst)))
270136 -- Variable expected
'

Would you rather write the classical definitions to a file and then load
that?

-- 
cheers,
Thorsten

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


Re: Method undefined - why?

2017-03-23 Thread Thorsten Jolitz
Joe Bogner  writes:

HiJoe,

> Hi Thorsen, what about using (class) and (dm) instead?
>
> joebo@joebo:~/dev/picoLisp$ pil + 
> : (class +Test) 
> -> +Test 
> : (dm T (Hi) (=: hi Hi)) 
> -> T 
> : (dm hi> (Nm) (or (text (: hi) Nm) "Dear Sir or Madam,")) 
> -> hi> 
> : (setq Foo (new '(+Test) "Hi @1")) 
> -> $177463554467256 
> : (hi> Foo "Alex") 
> -> "Hi Alex" 

yes, thats the more classical way, but I want to dynamically build the
class definition, so using (de) seems easier.

And I find it a bit strange that everything else works and looks good,
but not the method call in the code below.

This works

>  : (methods Foo)
>  -> ((T . +Test) (hi> . +Test))

but this not

>  : (hi> Foo "Alex")
>  !? (hi> Foo "Alex")
>  hi> -- Undefined

?

Should it work?
Does it work for others, but not for me?

This would be my questions ... ;-)

> On Thu, Mar 23, 2017 at 3:17 PM, Thorsten Jolitz
>  wrote:
>
>  Hi List,
>
>  playing around a bit wih Pil classes/object, here is something I
>  don't
>  understand:
>
>  #+BEGIN_SRC picolisp
>
>  : (de +Test
>  (T (Hi) (=: hi Hi))
>  (hi> (Nm) (or (text (: hi) Nm) "Dear Sir or Madam,")) )
>  -> +Test
>
>  : (setq Foo (new '(+Test) "Hi @1"))
>  -> $176777024346263
>
>  : (hi> Foo "Alex")
>  !? (hi> Foo "Alex")
>  hi> -- Undefined # => WHY?
>  ?
>
>  : (getl Foo)
>  -> (("Hi @1" . hi))
>
>  : (can 'hi>)
>  -> ((hi> . +Test))
>
>  : (type Foo)
>  -> (+Test)
>
>  : (show Foo)
>  $176777024346263 (+Test)
>  hi "Hi @1"
>  -> $176777024346263
>
>  : (methods Foo)
>  -> ((T . +Test) (hi> . +Test))
>
>  #+END_SRC
>
>  Is that strange, or is the problem sitting in front of the computer?
>
>  --
>  cheers,
>  Thorsten
>
>  --
>  UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>
>

-- 
cheers,
Thorsten

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


Re: Method undefined - why?

2017-03-23 Thread Joe Bogner
Hi Thorsen, what about using (class) and (dm) instead?

joebo@joebo:~/dev/picoLisp$ pil +
: (class +Test)
-> +Test
: (dm T (Hi) (=: hi Hi))
-> T
: (dm hi> (Nm) (or (text (: hi) Nm) "Dear Sir or Madam,"))
-> hi>
: (setq Foo (new '(+Test) "Hi @1"))
-> $177463554467256
: (hi> Foo "Alex")
-> "Hi Alex"



On Thu, Mar 23, 2017 at 3:17 PM, Thorsten Jolitz  wrote:

>
> Hi List,
>
> playing around a bit wih Pil classes/object, here is something I don't
> understand:
>
>
> #+BEGIN_SRC picolisp
>
> : (de +Test
>(T (Hi) (=: hi Hi))
>(hi> (Nm) (or (text (: hi) Nm) "Dear Sir or Madam,")) )
> -> +Test
>
> : (setq Foo (new '(+Test) "Hi @1"))
> -> $176777024346263
>
> : (hi> Foo "Alex")
> !? (hi> Foo "Alex")
> hi> -- Undefined  # => WHY?
> ?
>
> : (getl Foo)
> -> (("Hi @1" . hi))
>
> : (can 'hi>)
> -> ((hi> . +Test))
>
> : (type Foo)
> -> (+Test)
>
> : (show Foo)
> $176777024346263 (+Test)
>hi "Hi @1"
> -> $176777024346263
>
> : (methods Foo)
> -> ((T . +Test) (hi> . +Test))
>
> #+END_SRC
>
>
> Is that strange, or is the problem sitting in front of the computer?
>
> --
> cheers,
> Thorsten
>
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>