## Search found 119 matches

- Thu Oct 29, 2020 12:15 pm
- Forum: So, what can you actually DO with newLISP?
- Topic: Some functions on dates
- Replies:
**0** - Views:
**22**

### Some functions on dates

; julian day = 0 on monday 1 january 4713 B.C. (-4712 1 1) ;; @syntax (gdate-julian gdate) ;; @description Convert gregorian date to julian day number (valid only from 15 ottobre 1582 A.D.) ;; @param <gdate> gregorian date (year month day) ;; @return julian day number (int) ;; @example ;; (gdate-ju...

- Mon Oct 19, 2020 7:25 pm
- Forum: newLISP in the real world
- Topic: pow function problem
- Replies:
**2** - Views:
**203**

### Re: pow function problem

Thanks for the explanation

- Mon Oct 19, 2020 9:11 am
- Forum: newLISP in the real world
- Topic: pow function problem
- Replies:
**2** - Views:
**203**

### pow function problem

I have some problems with the pow function: (pow 3 0.33) ;-> 1.436977652184852 (pow -3 0.33) ;-> 1.#IND In Mathematica (WolframAlpha): 3^0.33 = 1.436977652184852 -3^0.33 = -1.436977652184852 A simple solution: (define (pow-ext x n) (if (< x 0) (sub 0 (pow (sub 0 x) n)) (pow x n))) (pow-ext 3 0.33) ;...

- Sun Oct 04, 2020 7:38 am
- Forum: newLISP in the real world
- Topic: select function for array
- Replies:
**0** - Views:
**137**

### select function for array

"select" function for array: (define (select-array arr lst-idx) (array (length lst-idx) (map (fn(x) (arr x)) lst-idx)) ) Some test: (setq lst '(3 5 6 7 1 9)) (setq vec (array (length lst) lst)) (select-array vec '(0 1)) ;-> (3 5) (select-array vec '(0 1 -1)) ;-> (3 5 9) (select-array vec '(-1 -2 -3 ...

- Wed Sep 23, 2020 12:10 pm
- Forum: newLISP in the real world
- Topic: Array or char bug?
- Replies:
**1** - Views:
**178**

### Re: Array or char bug?

Reading the manual for

This solve the problem (on UTF-8 enabled system):

**"char"**function...This solve the problem (on UTF-8 enabled system):

Code: Select all

```
(setf (ar (char (str 0) 0 true)) 555)
;-> 555
```

- Wed Sep 23, 2020 10:21 am
- Forum: newLISP in the real world
- Topic: Array or char bug?
- Replies:
**1** - Views:
**178**

### Array or char bug?

I have some problem to update an array: ; define an array (setq ar (array 256 '(-1))) ; define a string (setq str "bar") ; define an index (setq idx (char (str 0))) ;-> 98 (number? idx) ;-> true ; update array (setf (ar idx) 555) ;-> 555 (number? (char (str 0))) ;-> true ; update array fail (setf (a...

- Wed Sep 02, 2020 7:34 am
- Forum: newLISP in the real world
- Topic: using ref data
- Replies:
**5** - Views:
**371**

### Re: using ref data

Hi joejoe,

the "ref-all" and "ref" functions have a parameter to get data instead of indexes.
But maybe I misunderstood the question.

cameyo

the "ref-all" and "ref" functions have a parameter to get data instead of indexes.

Code: Select all

```
(setq lst '(a b c (d a f (a h a)) (k a (m n a) (x))))
(ref-all 'a lst)
;-> ((0) (3 1) (3 3 0) (3 3 2) (4 1) (4 2 2))
(ref-all 'a lst = true)
;-> (a a a a a a)
```

cameyo

- Thu Aug 13, 2020 11:20 am
- Forum: newLISP in the real world
- Topic: Find single number
- Replies:
**4** - Views:
**329**

### Re: Find single number

My solution using XOR:

Code: Select all

```
(define (find-number lst) (apply ^ lst))
(find-number '(1 3 1 2 3 4 5 2 4))
;-> 5
```

- Wed Aug 12, 2020 8:17 am
- Forum: newLISP in the real world
- Topic: Find single number
- Replies:
**4** - Views:
**329**

### Re: Find single number

Hi fdb,

thanks for your solution (hash table is nice).

There is a faster method using a boolean operator...

I'll post my solution in the next days.

cameyo

thanks for your solution (hash table is nice).

There is a faster method using a boolean operator...

I'll post my solution in the next days.

cameyo

- Tue Aug 11, 2020 8:52 am
- Forum: newLISP in the real world
- Topic: Find single number
- Replies:
**4** - Views:
**329**

### Find single number

Given a list of positive integers each number appears twice except one number. Find the single number.

Note: The function has to traverse the list only once (O(n)).

Note: The function has to traverse the list only once (O(n)).

- 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:
**865**

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

Maybe you can define 'f in a different way:
or
cameyo

Code: Select all

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

Code: Select all

```
(set (sym {''f}) 2)
;-> 2
(eval (sym {''f}))
;-> 2
```

- Thu Jul 09, 2020 4:12 pm
- Forum: newLISP in the real world
- Topic: List of user symbols
- Replies:
**0** - Views:
**1013**

### 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...

- Fri Jul 03, 2020 10:26 am
- Forum: newLISP in the real world
- Topic: Sum of integers in a string
- Replies:
**7** - Views:
**501**

### Re: Sum of integers in a string

thank you. I learned new things.

- Wed Jul 01, 2020 12:50 pm
- Forum: newLISP in the real world
- Topic: Sum of integers in a string
- Replies:
**7** - Views:
**501**

### 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) ...

- Tue Jun 30, 2020 3:37 pm
- Forum: newLISP in the real world
- Topic: Sum of integers in a string
- Replies:
**7** - Views:
**501**

### 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)

Write a function to calculate the sum of the integers inside a string (es. 22 + 62 + 0 = 84)

- Wed Jun 17, 2020 10:01 am
- Forum: newLISP in the real world
- Topic: Sorting nil and true
- Replies:
**1** - Views:
**330**

### Re: Sorting nil and true

I have found this method:
cameyo

Code: Select all

```
(setq lst '(true nil true b a))
(map sym (sort (map string lst)))
;-> (a b nil true true)
```

- Tue Jun 16, 2020 9:10 am
- Forum: newLISP in the real world
- Topic: Sorting nil and true
- Replies:
**1** - Views:
**330**

### Sorting nil and true

How to sort a list containing
Thanks

**nil**and**true**symbols?Code: Select all

```
(setq a '(nil true b a))
(sort a)
;-> (nil true a b)
```

- Wed Jun 03, 2020 9:36 am
- Forum: newLISP newS
- Topic: Forum is back again
- Replies:
**2** - Views:
**1328**

### Re: Forum is back again

Thanks to the administrator ... and to all the newlisp programmers

Massimo

Massimo

- Mon May 25, 2020 11:51 am
- Forum: newLISP in the real world
- Topic: From "The Little Schemer" to newLISP
- Replies:
**2** - Views:
**402**

### Re: From "The Little Schemer" to newLISP

Thanks newBert.

Wrong method of passing parameters in my function.

Wrong method of passing parameters in my function.

- Mon May 25, 2020 9:15 am
- Forum: newLISP in the real world
- Topic: From "The Little Schemer" to newLISP
- Replies:
**2** - Views:
**402**

### 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...

- Mon May 25, 2020 8:54 am
- Forum: newLISP in the real world
- Topic: Parallel assignment
- Replies:
**3** - Views:
**363**

### Re: Parallel assignment

Thanks !

I suspected that the

I suspected that the

**map**function could have been useful... :-)- Mon May 25, 2020 7:33 am
- Forum: newLISP in the real world
- Topic: Parallel assignment
- Replies:
**3** - Views:
**363**

### 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))) ; ...

- Sun Nov 24, 2019 2:02 pm
- Forum: newLISP in the real world
- Topic: Puzzle
- Replies:
**5** - Views:
**2248**

### 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...

- Sat Nov 23, 2019 1:38 pm
- Forum: newLISP in the real world
- Topic: Puzzle
- Replies:
**5** - Views:
**2248**

### Re: Puzzle

Hi fdb, nice solution :-)

However it is possible to solve the puzzle using a "normal" function with any programming language.

However it is possible to solve the puzzle using a "normal" function with any programming language.

- Thu Nov 21, 2019 1:05 pm
- Forum: newLISP in the real world
- Topic: Puzzle
- Replies:
**5** - Views:
**2248**

### Puzzle

Write a function f so that
I'll post the solution the next week :-)

**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
```