Re: Recursion-Loop Macro?

2017-02-13 Thread Lindsay John Lawrence
There is lots of discussion on the mail archive on this topic over the
years.
http://www.mail-archive.com/picolisp@software-lab.de/msg03860.html
There are others. Try searching tail recursion, macros, fexpr.

The mail archive has been an excellent source of information on picolisp.

I haven't found significant advantage to having tail recursion. Either in
picolisp, or other languages I generally work with.
Not recursing saves 'stack' but by the time that is an issue I am looking
for a different algorithm.

I am discovering picolisp has some great general purpose functions for just
that.

Here's an example I worked out recursively last week (set intersection),
then tried to do the same thing without recursion, then with (idx).
(randl, concurret, concurreti, concurretix are defined at the end of this
message)

# Make two lists of random numbers with random range large enough for small
collision set
: (nil (setq M (randl 1 999) N (randl 1 999)))
-> NIL

# Recurse
: (bench (sort (uniq (concurret M N
4.103 sec
-> (1144218 1809896 2048032 2258715 2819894 5571078 9413422 9726100 9936515)

# loop
: (bench (sort (uniq (concurreti M N
2.566 sec
-> (1144218 1809896 2048032 2258715 2819894 5571078 9413422 9726100 9936515)

# idx
: (bench (sort (uniq (concurretix M N
0.018 sec
-> (1144218 1809896 2048032 2258715 2819894 5571078 9413422 9726100 9936515)

Idx 'wins'.


/Lindsay


# ==
# Set intersection: recursive solution.
(de membro (X Y)
   (cond
  ((not Y) NIL)
  ((= X (car Y)) T)
  (T (membro X (cdr Y))) ) )

(de concurret (X Y)
   (cond
  ((not X) NIL)
  ((membro (car X) Y)
 (cons (car X) (concurret (cdr X) Y)) )
  (T (concurret (cdr X) Y)) ) )

# Set intersection: no recursion
(de membri (X Y)
   (until (or (not Y) (= X (car Y)))
  (setq Y (cdr Y)) )
   (= X (car Y)) )

(de concurreti (X Y)
   (let (V NIL)
  (until (not X)
 (when (membri (car X) Y)
(setq V (cons (car X) V)) )
 (setq X (cdr X)) )
  V ) )
# Set intersection: Filter X into (idx); filter Y on that.
(de concurretix (X Y)
   (let (R NIL)
  (filter
 '((V)
(not (idx 'R (cons (hash V) V) T)) )
 X )
  (uniq
 (filter
'((V) (idx 'R (cons (hash V) V)))
Y ) ) ) )

# Generate list of random numbers in given range
(de randl (L R) (make (do L (link (rand 0 R)


Re: trouble reading non blocking space etc

2017-02-13 Thread dean
Thank you very much for this!
I tried (cd src; make tools) both from the command line...because of "$"
and from within Picolisps RPL because of the parens.
I looked in src and there is just the utf2.c file.
When I do $ (cd src; make tools) from the command line I get...
$ (cd src; make tools)
*** Parse error in /home/me/picoLisp/src: Missing dependency operator
(Makefile:20)
*** Parse error: Need an operator in 'else' (Makefile:28)
*** Parse error: Missing dependency operator (Makefile:29)
*** Parse error: Need an operator in 'else' (Makefile:37)
etc.

which looks like
the block beginning
ifeg ($(shell uname), Linux)


Re: trouble reading non blocking space etc

2017-02-13 Thread Alexander Burger
Hi Dean,

> 6869 a074 6865 6972 3aa0 686f 7720 6172 6520 796f 750a
> hi.their:.how are you.
> 
> The following program...
> 
> (in "/home/me/test_fl.txt"
>(until (eof)
>   (setq Ln (line T))
>   (prinl Ln)))
> 
> results in this
> 
> hiനeir:ਯw are you

OK, as you noticed in your other mail, PicoLisp can handle *only* UTF-8 input.


> (load "@lib/import.l")

This is probably not necessary here.


> (in '("bin/utf8" "/home/me/test_fl.txt")

Good, that's the right way!


> bin/utf8: Can't exec

Try this:

   $ (cd src; make tools)

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


trouble reading non blocking space etc

2017-02-13 Thread dean
Hi
Here's a test file with it's hex above

6869 a074 6865 6972 3aa0 686f 7720 6172 6520 796f 750a
hi.their:.how are you.

The following program...

(in "/home/me/test_fl.txt"
   (until (eof)
  (setq Ln (line T))
  (prinl Ln)))

results in this

hiനeir:ਯw are you

I tried this

(load "@lib/import.l")
(in '("bin/utf8" "/home/me/test_fl.txt")

at the top of the program but got...

bin/utf8: Can't exec

I couldn't see a utf8 in /bin or picoLisp/bin

I suspect it's the A0 and : that's messing things up but am not sure what
to do about it.
Perl handles this fine by default but not if I tell it to do utf-8 encoding
i.e.
$ perl read_fl2.pl
utf8 "\xA0" does not map to Unicode at read_fl2.pl line 5.
utf8 "\xA0" does not map to Unicode at read_fl2.pl line 5.
got character h [U+0068]
got character i [U+0069]
got character \ [U+005c]
got character x [U+0078]
got character A [U+0041]
got character 0 [U+0030]
got character t [U+0074]

Any help to sort this out would be much appreciated.