Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - cameyo

#151
I use this function to group the elements of a list:
(define (take n lst) (slice lst 0 n))
(define (drop n lst) (slice lst n))

(define (group-by-num n lst)
   (if (null? lst) '()
      (cons (take n lst) (group-by-num n (drop n lst)))
   )
)

(setq lst '(0 1 2 3 4 5 6 7 8 9))

(group-by-num 2 lst)
;-> ((0 1) (2 3) (4 5) (6 7) (8 9))

(group-by-num 3 lst)
;-> ((0 1 2) (3 4 5) (6 7 8) (9))

(setq lst '(1 2 3 4 5 6 7 8 9 10 11 12))

(group-by-num 2 (group-by-num 2 lst))
;-> (((1 2) (3 4)) ((5 6) (7 8)) ((9 10) (11 12)))

Please, post your version.
#152
Wow!!!

Thanks fdb
#153
The magic of "map" :-)
#154
I use the following function to calculate the maximum nesting deep of a list:
(define (nesting lst)
  (cond ((null? lst) 0)
        ((atom? lst) 0)
        (true (max (+ 1 (nesting (first lst)))
                   (nesting (rest lst))))
  )
)

(nesting '(a (((b c (d)))) (e) ((f)) g))
;-> 5

Is there a better/faster way to do this?

Thanks.
#155
Grazie mille

Thank you so much
#156
Appunti sul linguaggio newLISP

00) Indice

01) newLISP in generale

02) Funzioni varie (44)

03) newLISP 99 problemi (28)

04) Rosetta code (26)

05) Project eulero (50)

06) Problemi vari (53)

07) Domande per assunzione di programmatori (28)

08) Librerie (4)

09) Appendici
#157
Thanks Lutz.

newLISP anywhere :-)
#158
Thanks Lutz.
> (setq a 1)
;-> 1
> (context 'A1)
;-> A1
A1> (symbols)
;-> ()
A1> a
;-> nil
A1> (symbols)
;-> (a)
#159
I have the following problem:
; create two contexts (A1, A2)
> (context 'A1)
;-> A1
A1> (context MAIN)
;-> MAIN
> (context 'A2)
;-> A2
A2> (context MAIN)
;-> MAIN
; create a variable "a"
> (setq a 2)
;-> 2
> (context 'A1)
;-> A1
; context A1 do not see the variable "a"
A1> a
;-> nil
; context A1 do not see the variable "a"
A1> (context 'A2)
;-> A2
A2> a
;-> nil
A2> (context MAIN)
;-> MAIN
> a
;-> 2

; set variabile "a" to global
(global 'a)

; but A1 and A2 do not see the variable "a"
> (context 'A1)
;-> A1
A1> a
;-> nil
A1> (context 'A2)
;-> A2
A2> a
;-> nil

But this works (do not check variable value on contexts before globalize it:

A2> (context MAIN)
;-> MAIN
> (context 'B2)
;-> B2
B2> (context MAIN)
;-> MAIN
> (context 'B1)
;-> B1
B1> (context MAIN)
;-> MAIN
> (setq b 3)
;-> 3
> (global 'b)
;-> b
> (context B1)
;-> B1
B1> b
;-> 3
B1> a
;-> 2
B1> (context B2)
;-> B2
B2> b
;-> 3
B2> a
;-> 2
B2>

B2> (context MAIN)
MAIN
; the context A1 see only "b" ("a" is nil)
> (context A1)
A1
A1> a
nil
A1> b
3
A1>

; change variable value
A1> (context MAIN)
MAIN
> (setq a 10)
10
> a
10
> (context B1)
B1
B1> a
10
B1> (context A1)
A1
A1> a
nil
A1>

Why A1 and A2 do not see the variable "a" ?

what am i doing wrong?

Is there a rule to define global variables and contexts?
#160
newLISP in the real world / Italian notes on newlisp
April 19, 2019, 02:26:31 AM
I'm writing some newlisp notes (in italian language):

https://github.com/cameyo42/newLISP-Note">//https://github.com/cameyo42/newLISP-Note

It is a work in progress and I am a beginner.

Advice, suggestions and corrections are welcome.

cameyo
#161
newLISP in the real world / Re: let and letn
March 05, 2019, 03:27:08 AM
I get:
(1 2 3 (4 5 6 7) (nil nil nil nil))
with newLISP 10.7.5 and 10.7.4 on windows 10.

cameyo
#162
newLISP and the O.S. / Re: Build newLISP for win10 64bit
February 20, 2019, 08:42:52 AM
@HPW: Thanks. All windows test passed.

Only one drawback: the file libffi-6.dll must be registered or saved in the same folder of newlisp.exe. Why?

cameyo
#163
newLISP and the O.S. / Re: Build newLISP for win10 64bit
February 19, 2019, 09:25:48 AM
@Lutz: which version of libffi ?

I have tried with prebuilt binaries of libffi 3.0.13-2 and libffi 3.2.1 and both works (compile and build newLISP.exe and newLISP.dll).

How to test the result ? Is there a program/script to test newLISP build ?

Thanks

cameyo
#164
newLISP and the O.S. / Re: Build newLISP for win10 64bit
February 19, 2019, 05:41:34 AM
@Lutz: Thanks. I'll try it this night :-)

Regards,

cameyo
#165
newLISP and the O.S. / Re: Build newLISP for win10 64bit
February 18, 2019, 10:36:26 AM
Update:



The "makefile_mingw64dll_utf8" gives an error on this statement:
gcc -m64 -shared *.o -Wl,--kill-at -lws2_32 -o newlisp.dll
gcc.exe: error: *.o: Invalid argument

To solve this i have changed the statement:
$(CC) -m64 -shared $(OBJS) -Wl,--kill-at -lws2_32 -o newlisp.dll
Now, i have some problems to build the ffi version of newLISP.

For example using the file "makefile_mingw64_utf8_ffi" i got the following error:
C:/TDM-GC~1/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
cannot find -lffi
collect2.exe: error: ld returned 1 exit status

on this line:
$(CC) -m64 $(OBJS) -lws2_32 -lffi -o newlisp.exe
Maybe the -lffi option is wrong ?

Some help?



cameyo