Search found 109 matches

by cameyo
Thu Jul 23, 2020 3:21 pm
Forum: Whither newLISP?
Topic: where is the value which is assigned by setq to a symbol?
Replies: 4
Views: 592

Re: where is the value which is assigned by setq to a symbol?

Maybe you can define 'f in a different way:

Code: Select all

(set (sym {'f}) 100)
;-> 100
(eval (sym {'f}))
;-> 100
or

Code: Select all

(set (sym {''f}) 2)
;-> 2
(eval (sym {''f}))
;-> 2
cameyo
by cameyo
Thu Jul 09, 2020 4:12 pm
Forum: newLISP in the real world
Topic: List of user symbols
Replies: 0
Views: 547

List of user symbols

A function to list the user symbols: (define (user-symbols) (local (_func _other) (setq _func '()) (setq _other '()) (dolist (_el (symbols)) (if (and (lambda? (eval _el)) (not (= _el 'user-symbols))) (push _el _func -1)) (if (and (not (lambda? (eval _el))) (not (primitive? (eval _el))) (not (protect...
by cameyo
Fri Jul 03, 2020 10:26 am
Forum: newLISP in the real world
Topic: Sum of integers in a string
Replies: 7
Views: 168

Re: Sum of integers in a string

thank you. I learned new things.
by cameyo
Wed Jul 01, 2020 12:50 pm
Forum: newLISP in the real world
Topic: Sum of integers in a string
Replies: 7
Views: 168

Re: Sum of integers in a string

Hi fdb, thanks for your functions. Only a problem: numbers with leading 0 will convert in octal base. Es. (parse-str "o123p010iru5") -> 136 (the correct value is 138) My function: (define (sum-str str) (local (numeri expr) (setq numeri '()) (setq expr {[0-9]+}) (replace expr str (push $0 numeri -1) ...
by cameyo
Tue Jun 30, 2020 3:37 pm
Forum: newLISP in the real world
Topic: Sum of integers in a string
Replies: 7
Views: 168

Sum of integers in a string

A string consist of digits and non-digit characters. The digits contains a series of positive integers. For instance, the string “abc22zit62de0f” contains the integers 22, 62 and 0.
Write a function to calculate the sum of the integers inside a string (es. 22 + 62 + 0 = 84)
by cameyo
Wed Jun 17, 2020 10:01 am
Forum: newLISP in the real world
Topic: Sorting nil and true
Replies: 1
Views: 127

Re: Sorting nil and true

I have found this method:

Code: Select all

(setq lst '(true nil true b a))
(map sym (sort (map string lst)))
;-> (a b nil true true)
cameyo
by cameyo
Tue Jun 16, 2020 9:10 am
Forum: newLISP in the real world
Topic: Sorting nil and true
Replies: 1
Views: 127

Sorting nil and true

How to sort a list containing nil and true symbols?

Code: Select all

(setq a '(nil true b a))
(sort a)
;-> (nil true a b)
Thanks
by cameyo
Wed Jun 03, 2020 9:36 am
Forum: newLISP newS
Topic: Forum is back again
Replies: 1
Views: 555

Re: Forum is back again

Thanks to the administrator ... and to all the newlisp programmers
Massimo
by cameyo
Mon May 25, 2020 11:51 am
Forum: newLISP in the real world
Topic: From "The Little Schemer" to newLISP
Replies: 2
Views: 181

Re: From "The Little Schemer" to newLISP

Thanks newBert.
Wrong method of passing parameters in my function.
by cameyo
Mon May 25, 2020 9:15 am
Forum: newLISP in the real world
Topic: From "The Little Schemer" to newLISP
Replies: 2
Views: 181

From "The Little Schemer" to newLISP

I am reading the book "The Little Schemer" (yes, i know newLISP is different from Scheme...but i'm learning) Until chapter 8 i had no problem to translate the code in newLISP. But now i have the following function: (define (rember-f test?) (lambda (a l) (cond ((null? l) '()) ((test? (first l) a) (re...
by cameyo
Mon May 25, 2020 8:54 am
Forum: newLISP in the real world
Topic: Parallel assignment
Replies: 3
Views: 147

Re: Parallel assignment

Thanks !
I suspected that the map function could have been useful... :-)
by cameyo
Mon May 25, 2020 7:33 am
Forum: newLISP in the real world
Topic: Parallel assignment
Replies: 3
Views: 147

Parallel assignment

Hi all, this is my first macro to do parallel assignment: (define-macro (psetq) (let ((_var '()) (_ex '())) ; for each expression in (args 1) ... (for (i 0 (- (length (args 1)) 1)) ; expand the i-th expression with the value ; of each variable in (args 0) (setq _ex (expand (args 1 i) (args 0 0))) ; ...
by cameyo
Sun Nov 24, 2019 2:02 pm
Forum: newLISP in the real world
Topic: Puzzle
Replies: 5
Views: 1910

Re: Puzzle

@ralph.ronnquist : you right :-) @fbd : another good lisp-style solution Solution: One method is to separate the sign and magnitude of the number by the parity of the number. We have three cases: 1) If the number is even, it keeps the same sign and moves 1 closer to 0 (subtract 1 from a positive ev...
by cameyo
Sat Nov 23, 2019 1:38 pm
Forum: newLISP in the real world
Topic: Puzzle
Replies: 5
Views: 1910

Re: Puzzle

Hi fdb, nice solution :-)
However it is possible to solve the puzzle using a "normal" function with any programming language.
by cameyo
Thu Nov 21, 2019 1:05 pm
Forum: newLISP in the real world
Topic: Puzzle
Replies: 5
Views: 1910

Puzzle

Write a function f so that f (f (n)) = -n for every integer n.

Code: Select all

Examples:
(f (f -1)) = 1
(f (f 1)) = -1
(f (f 4)) = -4
(f (f -4)) = 4
(f (f 0)) = 0
I'll post the solution the next week :-)
by cameyo
Thu Nov 21, 2019 8:03 am
Forum: newLISP in the real world
Topic: Fractran language
Replies: 4
Views: 895

Re: Fractran language

Thanks for another function for big integer :-)
by cameyo
Wed Nov 20, 2019 7:20 pm
Forum: newLISP in the real world
Topic: Fractran language
Replies: 4
Views: 895

Re: Fractran language

Hi ralph.ronnquist,
i have some problems with your function.
I think that the bits function don't work with big integer.

Have a nice day
by cameyo
Mon Nov 18, 2019 3:51 pm
Forum: newLISP in the real world
Topic: Fractran language
Replies: 4
Views: 895

Fractran language

Fractran is a Turing-complete esoteric programming language invented by the mathematician John Conway. A Fractran program is an ordered list of positive fractions together with an initial positive integer input n. The program is run by updating the integer n as follows: 1) For the first fraction f i...
by cameyo
Fri Nov 01, 2019 2:40 pm
Forum: newLISP in the real world
Topic: Tree structure
Replies: 2
Views: 820

Re: Tree structure

Some basic functions on binary trees. Maybe these can be useful to other beginners like me... List structure of a tree --> (V L R) where V = tree Value L = Left sub-tree R = Right sub-tree leaf --> (V nul nul) Example: A / \ / \ B C / / \ / / \ D E F (setq my-tree '(A (B (D nul nul)) (C (E nul nul) ...
by cameyo
Wed Oct 30, 2019 5:04 pm
Forum: newLISP in the real world
Topic: Tree structure
Replies: 2
Views: 820

Re: Tree structure

To start:
"Simply Scheme" Harvey-Wright (Chapter 18)
"SICP" Abelman-Sussman (2.2.2 Hierarchical Structures)
...
binary trees, binary search trees, AVL trees, 2-3-4 trees, red-black trees... it is a long road :-)
by cameyo
Mon Oct 21, 2019 10:10 am
Forum: newLISP in the real world
Topic: Tree structure
Replies: 2
Views: 820

Tree structure

Which is the best way to represent a tree with a list?
Do you know newLISP code that works with trees?
Thanks
by cameyo
Fri Oct 04, 2019 9:22 am
Forum: newLISP in the real world
Topic: difference result by eval in macro and in S-expr
Replies: 5
Views: 1060

Re: difference result by eval in macro and in S-expr

Hi lyl,
i'm not an expert, but i think "evaluated" is different from "expanded". Maybe a guru will highligth this question.
The typeof function show the type of the argument; the core function is dump (see the manual for information).
ciao
by cameyo
Thu Oct 03, 2019 6:22 pm
Forum: newLISP in the real world
Topic: difference result by eval in macro and in S-expr
Replies: 5
Views: 1060

Re: difference result by eval in macro and in S-expr

Maybe you can use letex : (define(f lst) (letex (x lst) (+ x 1))) (setq a '(+ 2 3)) ;-> (+ 2 3) (f a) ;-> 6 Try this: (define types '("nil" "true" "int" "float" "string" "symbol" "context" "primitive" "import" "ffi" "quote" "expression" "lambda" "fexpr" "array" "dyn_symbol")) (define (typeof v) (typ...
by cameyo
Thu Sep 26, 2019 10:56 am
Forum: So, what can you actually DO with newLISP?
Topic: Quine
Replies: 0
Views: 1734

Quine

A Quine on REPL:

Code: Select all

ERR: context expected : ERR:
;-> ERR: context expected : ERR:
Have a nice day