Search found 183 matches

by cameyo
Fri Jun 14, 2019 5:16 pm
Forum: newLISP in the real world
Topic: How to partially evaluate elements in a hash-table
Replies: 5
Views: 4843

Re: How to partially evaluate elements in a hash-table

Maybe this:

Code: Select all

(setq a '(((+ 6 2) (a) 2) ((- 2 5) (b) 5)))
;-> (((+ 6 2) (a) 2) ((- 2 5) (b) 5))
(dolist (el a)
 (setf (first (a $idx)) (eval (first el)))
)
a
;-> ((8 (a) 2) (-3 (b) 5))
by cameyo
Fri Jun 14, 2019 7:14 am
Forum: newLISP in the real world
Topic: How to partially evaluate elements in a hash-table
Replies: 5
Views: 4843

Re: How to partially evaluate elements in a hash-table

Try this:

Code: Select all

(map (fn (x) (eval (first x))) mytable)
;-> (97 98)
by cameyo
Fri Jun 07, 2019 9:05 am
Forum: newLISP newS
Topic: newLISP language support for Visual Studio Code
Replies: 9
Views: 11289

Re: newLISP language support for Visual Studio Code

Hi fdb,
I have installed VS Code and your extension in a new PC.
'Alt+L' and 'Alt+Z' don't work in my system.
I'll try it on Mac this weekend.
Thanks for your work
cameyo
by cameyo
Thu Jun 06, 2019 7:04 pm
Forum: newLISP newS
Topic: newLISP language support for Visual Studio Code
Replies: 9
Views: 11289

Re: newLISP language support for Visual Studio Code

I have tried the extension on windows. The syntax highlighting is nice. The command 'alt+z' and 'alt+l' don't work on my system. The errors are: "Command 'newlisp.eval' not found" and "Command 'newlisp.evalFile' not found" (see image: https://imgur.com/a/w3QBMws ) To eval newlisp statements i do the...
by cameyo
Tue Jun 04, 2019 1:18 pm
Forum: newLISP in the real world
Topic: Equal and Not Equal
Replies: 1
Views: 2234

Re: Equal and Not Equal

After starting a new newLISP REPL...all works ok :-)
It is not the first time that I get strange results after using the debugger.
I'd like to have a command/method to test the integrity/correctness of current REPL session.
cameyo
by cameyo
Tue Jun 04, 2019 12:57 pm
Forum: newLISP in the real world
Topic: Equal and Not Equal
Replies: 1
Views: 2234

Equal and Not Equal

Code: Select all

(setq lst '((2 4) (3 1)))

(= (lst 0 0) (lst 0 0))
;-> true

(!= (lst 0 0) (lst 0 0))
;-> (nil nil)

(= (lst 0 0) (lst 1 0))
;-> (nil nil)

(= (first (first lst)) (last (first lst)))
;-> (nil nil)
I was expecting nil, instead i got (nil nil).
Where am I doing wrong?
Thanks.
by cameyo
Mon Jun 03, 2019 10:49 am
Forum: newLISP in the real world
Topic: Sum of digits
Replies: 4
Views: 4380

Re: Sum of digits

Yes, rickyboy. A very elegant solution.
Thanks for the italian translation :-)
by cameyo
Mon Jun 03, 2019 7:55 am
Forum: newLISP in the real world
Topic: Sum of digits
Replies: 4
Views: 4380

Sum of digits

Given a number n, find the sum of its digits until sum becomes single digit.

Code: Select all

Example: n = 7865 = 7 + 8 + 6 + 5 = 26 ==> 2 + 6 = 8

Code: Select all

(define (digitSum n)
  (if (zero? n) 0
    (if (zero? (% n 9)) 9
      (% n 9))))

(digitSum 236753647864)
;-> 7
by cameyo
Sun Jun 02, 2019 2:02 pm
Forum: newLISP newS
Topic: newLISP language support for Visual Studio Code
Replies: 9
Views: 11289

Re: newLISP language support for Visual Studio Code

Hi fdb,
with notepad++ i never write text on REPL.
Left Shift + Enter -> Evaluate current line
Rigth Shift + Enter -> Evaluate current selection
Alt + F1 Open local newlisp help for selected keyword.
cameyo
by cameyo
Sun Jun 02, 2019 11:12 am
Forum: newLISP newS
Topic: newLISP language support for Visual Studio Code
Replies: 9
Views: 11289

Re: newLISP language support for Visual Studio Code

Thanks fdb!!!
I use notepad++, but i'd like to use VSCode on mac :-)
I'll try it as soon as possible.
It's possible to execute the current line on newLISP REPL?
It's possible to execute the active selection on newLISP REPL?
Thanks again.
cameyo
by cameyo
Fri May 31, 2019 6:07 am
Forum: newLISP in the real world
Topic: Maximum Product Sublist
Replies: 5
Views: 4265

Re: Maximum Product Sublist

Hi rickyboy and ralph.ronnquist,
you're very friendly and competent.
And yes, newLISP is fun.
Have a nice day.
cameyo
by cameyo
Thu May 30, 2019 7:42 pm
Forum: newLISP in the real world
Topic: Maximum Product Sublist
Replies: 5
Views: 4265

Re: Maximum Product Sublist

Hi rickyboy,
the sublist must contains only contiguous elements.
But your functions are useful anyway :-)
by cameyo
Thu May 30, 2019 6:14 pm
Forum: newLISP in the real world
Topic: Group the elements of a list
Replies: 10
Views: 6492

Re: Group the elements of a list

I need more time to understand all this...
by cameyo
Thu May 30, 2019 5:28 pm
Forum: newLISP in the real world
Topic: Maximum Product Sublist
Replies: 5
Views: 4265

Maximum Product Sublist

Maximum Product Sublist Given a list that contains both positive and negative integers, find the product of the maximum product sublist. (define (maxProd lst) (local (n maxprod pos neg) (setq n (length lst)) (setq pos (array n '(0))) (setq neg (array n '(0))) (setq (pos 0) (lst 0)) ; pos[i] contains...
by cameyo
Wed May 29, 2019 9:01 am
Forum: newLISP in the real world
Topic: Group the elements of a list
Replies: 10
Views: 6492

Re: Group the elements of a list

Thanks to all. I have learned a lot.
by cameyo
Tue May 28, 2019 7:16 pm
Forum: newLISP in the real world
Topic: Group the elements of a list
Replies: 10
Views: 6492

Re: Group the elements of a list

damn :-)
by cameyo
Tue May 28, 2019 10:35 am
Forum: newLISP in the real world
Topic: Group the elements of a list
Replies: 10
Views: 6492

Group the elements of a list

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...
by cameyo
Tue May 28, 2019 6:09 am
Forum: newLISP in the real world
Topic: Nesting level of a list
Replies: 5
Views: 4014

Re: Nesting level of a list

Wow!!!
Thanks fdb
by cameyo
Mon May 27, 2019 9:02 pm
Forum: newLISP in the real world
Topic: Nesting level of a list
Replies: 5
Views: 4014

Re: Nesting level of a list

The magic of "map" :-)
by cameyo
Mon May 27, 2019 8:50 am
Forum: newLISP in the real world
Topic: Nesting level of a list
Replies: 5
Views: 4014

Nesting level of a list

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.
by cameyo
Tue May 14, 2019 5:11 pm
Forum: newLISP newS
Topic: Stable Release newLISP v.10.7.5
Replies: 10
Views: 14184

Re: Stable Release newLISP v.10.7.5

Grazie mille
Thank you so much
by cameyo
Wed May 08, 2019 5:58 pm
Forum: newLISP in the real world
Topic: Italian notes on newlisp
Replies: 1
Views: 2496

Re: Italian notes on newlisp

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
by cameyo
Wed May 08, 2019 6:58 am
Forum: newLISP newS
Topic: newLISP in a browser - new version
Replies: 6
Views: 10079

Re: newLISP in a browser - new version

Thanks Lutz.
newLISP anywhere :-)
by cameyo
Thu May 02, 2019 11:22 am
Forum: newLISP in the real world
Topic: Contexts and global variables
Replies: 2
Views: 3314

Re: Contexts and global variables

Thanks Lutz.

Code: Select all

> (setq a 1)
;-> 1
> (context 'A1)
;-> A1
A1> (symbols)
;-> ()
A1> a
;-> nil
A1> (symbols)
;-> (a)