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

#61
Thanks again.

I'll test both methods for speed and simplicity.
#62
It works.

But I would also need to pass the function name as a parameter, for example:
(make-adder "add10" 10)
Thanks again for the help
#63
Thank you, but it doesn't works. The symbol y is not binded.

I am looking for the most suitable/fastest method of generating functions automatically (passing name of function and parameters).
#64
newLISP in the real world / IDE for newLISP
April 08, 2021, 06:33:49 AM
On the web I found this IDE for newLISP:

https://github.com/DexterLagan/newIDE">//https://github.com/DexterLagan/newIDE

by Dexter Santucci



cameyo
#65
Variable symbols should not start with any of the following characters:

# ; " ' ( ) { } . , 0 1 2 3 4 5 6 7 8 9



see "Syntax of symbol variables and numbers" on newLISP manual
#66
Function to create a function with name and parameters:
(define (make-add name val)
  (let (f nil)
    (setq f (string "(define (" name " x) (+ " val " x))"))
    (setq name (eval-string f))
  name))

Creating a function
(make-add "sum-10" 10)
out: (lambda (x) (+ 10 x))

Using the created function
(sum-10 3)
out: 13

Do you know of another way (instead of using strings) to create a function with another function?
#67
Very nice.

Thank you.
#68
Windows and MacOS. But I can wait without any problems.

Thank you.
#69
Thanks.

When will be released a compiled version?

Best regards,

cameyo
#70
I have the following situation:
(setq j (array 256 '(-1)))
(setq str "abc")
(char (str 1))
;-> 98
(integer? (char (str 1)))
;-> true

Now i want to update a value of the array j:

Using the number 98 works:
(setf (j 98) 2)
;-> 2

Reference with a variable works too:
(setq idx (char (str 1)))
;-> 98
(setf (j idx) 2)
;-> 2

Why the following expressions raise an error?
(setf (j (char (str 1))) 2)
;-> ERR: string expected : 2

Using a string as value works:
(setf (j (char (str 1))) "2")
;-> "2"

Thanks.
#71
A pandigital magic square (found with newLISP) having n^2 distinct pandigital integers and having the smallest pandigital magic sum.



  1035629784 1035728694 1024638795 1024739685

  1025639784 1025738694 1034628795 1034729685

  1035729684 1035628794 1024738695 1024639785

  1025739684 1025638794 1034728695 1034629785



Magic sum = 4120736958 (pandigital)
#72
newLISP in the real world / Project Euler
February 12, 2021, 12:08:12 AM
Project Euler https://projecteuler.net/">//https://projecteuler.net/ added newLISP language.

I have solved 102 problems: 1..102.



cameyo
#73
; 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-julian '(2019 11 11))  ==> 2458799
;; (gdate-julian '(2019 11 12))  ==> 2458800
;; (gdate-julian '(-4712 1 1))   ==> 38
(define (gdate-julian gdate)
  (local (a y m)
    (setq a (/ (- 14 (gdate 1)) 12))
    (setq y (+ (gdate 0) 4800 (- a)))
    (setq m (+ (gdate 1) (* 12 a) (- 3)))
    (+ (gdate 2) (/ (+ (* 153 m) 2) 5) (* y 365) (/ y 4) (- (/ y 100)) (/ y 400) (- 32045))))

;; @syntax (jdate-julian jdate)
;; @description Convert julian date to julian day number (valid only until 4 ottobre 1582 A.D.)
;; @param <jdate> julian date (year month day)
;; @return julian day number (int)
;; @example
;; (jdate-julian '(2019 11 11))  ==> 2458812
;; (jdate-julian '(2019 11 12))  ==> 2458813
;; (jdate-julian '(-4712 1 1))   ==> 0
(define (jdate-julian jdate)
  (local (a y m)
    (setq a (/ (- 14 (jdate 1)) 12))
    (setq y (+ (jdate 0) 4800 (- a)))
    (setq m (+ (jdate 1) (* 12 a) (- 3)))
    (+ (jdate 2) (/ (+ (* 153 m) 2) 5) (* y 365) (/ y 4) (- 32083))))

;; @syntax (julian-gdate jd)
;; @description Convert julian day number to gregorian date (valid only from 15 ottobre 1582 A.D.)
;; @param <jd> julian day number (int)
;; @return gregorian date (year month day)
;; @example
;; (julian-gdate 2458799)                       ==> (2019 11 11)
;; (julian-gdate 2458800)                       ==> (2019 11 12)
;; (julian-gdate (gdate-julian '(2019 11 12)))  ==> (2019 11 12)
(define (julian-gdate jd)
  (local (a b c d e m)
    (setq a (+ jd 32044))
    (setq b (/ (+ (* 4 a) 3) 146097))
    (setq c (- a (/ (* b 146097) 4)))
    (setq d (/ (+ (* 4 c) 3) 1461))
    (setq e (- c (/ (* 1461 d) 4)))
    (setq m (/ (+ (* 5 e) 2) 153))
    (list
      (+ (* b 100) d (- 4800) (/ m 10))
      (+ m 3 (- (* 12 (/ m 10))))
      (+ e (- (/ (+ (* 153 m) 2) 5)) 1))))

;; @syntax (julian-jdate jd)
;; @description Convert julian day number to julian date (valid only until 4 ottobre 1582 A.D.)
;; @param <jd> julian day number (int)
;; @return julian date (year month day)
;; @example
;; (julian-jdate 2458812)  ==> (2019 11 11)
;; (julian-jdate 2458813)  ==> (2019 11 12)
;; (julian-jdate 0)        ==> (-4712 1 1)
(define (julian-jdate jd)
  (local (a b c d e m)
    (setq a 0)
    (setq b 0)
    (setq c (+ jd 32082))
    (setq d (/ (+ (* 4 c) 3) 1461))
    (setq e (- c (/ (* 1461 d) 4)))
    (setq m (/ (+ (* 5 e) 2) 153))
    (list
      (+ (* b 100) d (- 4800) (/ m 10))
      (+ m 3 (- (* 12 (/ m 10))))
      (+ e (- (/ (+ (* 153 m) 2) 5)) 1))))

;; @syntax (julian-weekday jd)
;; @description Find the day of week (number) of a julian day number
;; @param <jd> julian day number (int)
;; @return day of week number (ISO: Mon=1 ... Sun=7) (int)
;; @example
;; (julian-weekday (gdate-julian '(1900 3 15)))  ==> 4
;; (julian-weekday (gdate-julian '(1821 5 5)))   ==> 6
;; (julian-weekday (jdate-julian '(1400 1 1)))   ==> 4
(define (julian-weekday jd) (+ (% jd 7) 1))

;; @syntax (gdate-diff gdate1 gdate2)
;; @description Calculate the difference between two gregorian dates
;; @param <gdate1> first gregorian date (year month day)
;; @param <gdate2> second gregorian date (year month day)
;; @return (date1 - date2 = interval of days) (int)
;; @example
;; (gdate-diff '(2012 11 28) '(2010 4 22))  ==> 951
(define (gdate-diff gdate1 gdate2)
  (- (gdate-julian gdate1) (gdate-julian gdate2)))

;; @syntax (gdate-add gdate num-days)
;; @description Adds days to a gregorian date
;; @param <gdate> gregorian date (year month day)
;; @param <num-days> days to add (int)
;; @return gregorian date (year month day)
;; @example (gdate-add '(1980 3 15) 10)  ==> (1980 3 25)
(define (gdate-add gdate num-days)
  (julian-gdate (+ (gdate-julian gdate) num-days)))

;; @syntax (gdate-sub gdate num-days)
;; @description Subtracts days from a gregorian date
;; @param <gdate> gregorian date (year month day)
;; @param <num-days> days to sub (int)
;; @return gregorian date (year month day)
;; @example
;; (gdate-sub '(1980 3 15) 31)  ==> (1980 2 13)
(define (gdate-sub gdate num-days)
  (julian-gdate (- (gdate-julian gdate) num-days)))
#74
newLISP in the real world / Re: pow function problem
October 19, 2020, 12:25:46 PM
Thanks for the explanation
#75
newLISP in the real world / pow function problem
October 19, 2020, 02:11:55 AM
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)
;-> 1.436977652184852
;(pow-ext -3 0.33)
;-> -1.436977652184852

Why newLISP result is 1.#IND?