Re: iterate over list until you find a match

2016-11-23 Thread dean
Alex
Thank you very much for this.
Best Regards
Dean

On 23 November 2016 at 21:00, Alexander Burger  wrote:

> Hi Dean,
>
> > I'm just wondering what my options are re doing this
> >
> > (de mmbr (Trgt L)
> >(for Ele L
> >   (if (== Ele Trgt) (println "found so exit with true")
> > (println "try next")
> >   )
> >)
> >(prinl "list exhausted so return false")
> > )
> >
> > (mmbr 'B '(A B C))
> >
> > I only know how to iterate over lists using for but don't know how to
> exit
> > for.
>
> For simply finding an element in a list, you can use 'member' or 'memq'
>
>(memq 'B '(A B C))
>
> It returns the restlist, or NIL if not found.
>
>
> To implement it yourself, you could do
>
>(de mmbr (Trgt L)
>   (for Ele L
>  (T (== Ele Trgt) T) ) )
>
>: (mmbr 'B '(A B C))
>-> T
>
>: (mmbr 'D '(A B C))
>-> NIL
>
>
> > I also saw find...but wasn't sure exactly how I'd apply that.
>
>: (find '((X) (== X 'B)) '(A B C))
>-> B
>
>
> > BTW which is the most efficient loop in Picolisp from an execution
> > perspective?
>
> I would say 'while' and 'until', or 'do' for counted loops.
>
> You can experiment with 'bench' to compare the relative speeds.
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


Re: iterate over list until you find a match

2016-11-23 Thread Alexander Burger
Hi Dean,

> I'm just wondering what my options are re doing this
> 
> (de mmbr (Trgt L)
>(for Ele L
>   (if (== Ele Trgt) (println "found so exit with true")
> (println "try next")
>   )
>)
>(prinl "list exhausted so return false")
> )
> 
> (mmbr 'B '(A B C))
> 
> I only know how to iterate over lists using for but don't know how to exit
> for.

For simply finding an element in a list, you can use 'member' or 'memq'

   (memq 'B '(A B C))

It returns the restlist, or NIL if not found.


To implement it yourself, you could do

   (de mmbr (Trgt L)
  (for Ele L
 (T (== Ele Trgt) T) ) )

   : (mmbr 'B '(A B C))
   -> T

   : (mmbr 'D '(A B C))
   -> NIL


> I also saw find...but wasn't sure exactly how I'd apply that.

   : (find '((X) (== X 'B)) '(A B C))
   -> B


> BTW which is the most efficient loop in Picolisp from an execution
> perspective?

I would say 'while' and 'until', or 'do' for counted loops.

You can experiment with 'bench' to compare the relative speeds.

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


Re: read in Pilog - SOLVED

2016-11-23 Thread CILz

Alex, you rock! Thanks very much. Eric


Le 23/11/2016 à 20:23, Alexander Burger a écrit :

  : (be read (@X)
   (^ @X (read)) )
-> read

: (? (read @A))
(foo bar)
 @A=(foo bar)


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


iterate over list until you find a match

2016-11-23 Thread dean
I'm just wondering what my options are re doing this

(de mmbr (Trgt L)
   (for Ele L
  (if (== Ele Trgt) (println "found so exit with true")
(println "try next")
  )
   )
   (prinl "list exhausted so return false")
)

(mmbr 'B '(A B C))

I only know how to iterate over lists using for but don't know how to exit
for.
until might be more suitable suitable but I don't know how to look at each
member using it.
I also saw find...but wasn't sure exactly how I'd apply that.
Any help much appreciated.
BTW which is the most efficient loop in Picolisp from an execution
perspective?


Re: read in Pilog

2016-11-23 Thread Alexander Burger
On Wed, Nov 23, 2016 at 07:19:05PM +0100, CILz wrote:
> Alex, thanks for being so patient! I came up with this:
> 
> (be p_read ()
>   (^ @ (read)) )
> 
> which looks to work so far ;-).
> 
> However I wonder if there is a way to catch and unify the read value to a
> variable.

   : (be read (@X)
  (^ @X (read)) )
   -> read

   : (? (read @A))
   (foo bar)
@A=(foo bar)

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


Re: read in Pilog

2016-11-23 Thread CILz

Alex, thanks for being so patient! I came up with this:

(be p_read ()
  (^ @ (read)) )

which looks to work so far ;-).

However I wonder if there is a way to catch and unify the read value to 
a variable.


For example in Prolog the predicate 'read/1' allows to catch in 
'read(Value)' where 'Value' can be passed to an other predicate. Can I 
do the same here.


Thanks,
Eric

Le 23/11/2016 à 13:15, Alexander Burger a écrit :

Here too some Lisp function must be called.


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


Re: read in Pilog

2016-11-23 Thread Alexander Burger
Hi Eric,

> Is there a way to have something similar to 'read' in Pilog?

Here too some Lisp function must be called.

However, it depends what you mean with "read": You can call the 'read'
function which reads s-expressions in Lisp syntax (or lists of tokens
when called with an additional arguments), or the lower-level 'char',
'line', 'till' etc. functions. Or even 'rd' for binary or PLIO reading.

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


Re: typo in tutorial re 'till' ?

2016-11-23 Thread dean
Hi Alex
You're very welcome,

On 23 November 2016 at 10:53, Alexander Burger  wrote:

> On Wed, Nov 23, 2016 at 09:52:32AM +, dean wrote:
> > resulting in bad input rather than "fact"
> > : (in "@doc/fun.l" (from "(de ") (till " " T)))
>
> Thanks Dean! Fixed in next release.
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


read in Pilog

2016-11-23 Thread CILz

Is there a way to have something similar to 'read' in Pilog?

Thanks,

Eric

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


typo in tutorial re 'till' ?

2016-11-23 Thread dean
Not a big deal but... it seems there is one too many ')' on the end
resulting in bad input rather than "fact"
: (in "@doc/fun.l" (from "(de ") (till " " T)))
-> "fact"


Re: How to display some text in Pilog - SOLVED

2016-11-23 Thread CILz

Hello Alex,

Thank you very much, that's it.

In fact, I have tried this solution before asking on the list, however 
as I am still not very fluent in Lisp I have written :


: (be intro

(prin "Hello world\n") )

without the two >> () << at the beginning of the defintion of the 
predicate!!


Best,

Eric


Le 23/11/2016 à 09:27, Alexander Burger a écrit :

   : (be intro ()
   (prin "Hello world\n") )
-> intro

:  (? (intro))
Hello world
-> T

Is this what you mean?


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