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 - newBert

#16
Just another way to do it (with what comes to hand):


> (setq x 2 y 3)
3
> (map set '(x y) (list (+ 1 y) (+ 1 x)))
(4 3)

> (setq x 1 y 2 z 3)
3
> (map set '(x y z) (list (+ x y z) (- z y x) (- x y z)))
(6 0 -4)
 


:)
#17
Quote from: "lyl"My quesstion is:

Is there an universal method to determine whether a list can be evaluated or not?


Oops ! Why didn't I think of  catch ?


> (setq a '(1 2 3))
(1 2 3)
> (catch (eval a) 'result)
nil  ; `a` can't be evaluated (see error below in `result`)
> result
"ERR: illegal parameter type in function eval : 2"

> (setq b '(1 a))
(1 a)
> (catch (eval b) 'result)
true  ; `b` can be evaluated (see `result`)
> result
(2 3)

> (setq c '(+ 1 2))
(+ 1 2)
> (catch (eval c) 'result)
true
> result
3
>
#18
newLISP Graphics & Sound / Re: Combo-box
May 24, 2020, 03:19:05 AM
Sorry for the late answer, but the forum was inaccessible for a moment.

I think the solution is in "widgets-demo.lsp".

Maybe you should use 'base64-dec' to decode the value of combo-box.
#19
Quote from: "lyl"(setq a '(1 2 3)) ;; This list can not be evaled

It's normal, because '1' is neither a primitive nor a lambda


Quote(setq b '(1 a)) ;; This list can be evaled, (eval b) --> (2 3)

Also normal, because  (1 a) is equivalent to (rest a) <- implicit indexing


Quote(setq c '(+ 1 2)) ;; This list can be evaled, (eval c) --> 3

Normal, because '+' is a primitive


QuoteMy quesstion is:

Is there an universal method to determine whether a list can be evaluated or not?

Maybe testing wether the first member of the quoted list is a primitive or a lambda ?...



> (setq a '(1 2 3))
(1 2 3)
> (or (lambda? (eval (first a))) (primitive? (eval (first a))))
nil
> (eval a)
ERR: illegal parameter type in function eval : 2

> (setq b '(1 a))
(1 a)
> (or (lambda? (eval (first b))) (primitive? (eval (first b))))
nil
>(eval b)
(2 3)

> (setq c '(+ 1 2))
(+ 1 2)
> (or (lambda? (eval (first c))) (primitive? (eval (first c))))
true
> (eval c)
3


But it doesn't work for 'b', so it's not really "universal" !
#20
Indeed, I've just tried again now, in a new NewLISP session, and I get the expected result: (1 2 3 (4 5 6 7) (nil nil nil nil)). I'm reassured :). Thank you , RalphRonnquist, Cameyo and Rickyboy for your replies and advice.

I don't know what could have happened... I probably forgot NewLISP has no lexical scoping by default.
#21
newLISP in the real world / let and letn
March 04, 2019, 05:30:46 AM
I don't understand why letn isn't required here, or why let doesn't cause an error:
(let (a 1 b 2 c 3 d '(4 5 6 7) e (flat (list a b c d)))
  (println (list a b c d e)))
;−> (1 2 3 (4 5 6 7) (1 2 3 4 5 6 7))
#22
(With some delay...)

I think we could also write: (set 'funclist (list myfunc myfunc myfunc myfunc myfunc)), so we don't need 'eval' in (set 'afunc (funclist 2))
#23
Quote from: "lyl"
Quote from: "newBert"Here is a solution (probably not the only one, nor the best) :
newLISP v.10.7.5 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h

> (select '(0 1 2 3 4) (difference (index true? '(0 1 2 3 4)) '(1 2)))
(0 3 4)
> ;; maybe clearer:
>
(let (lst '(0 1 2 3 4))
  (select lst (difference (index true? lst) '(1 2))))

(0 3 4)
>


If the lst contains nil(0 1 2 3 nil), how to do?


I replaced 0 1 2 3 4... with a b c d e... for clarity.
>
(let (lst '(a b c d nil f))
  (select lst (difference (sequence 0 (- (length lst) 1)) '(1 2))))

(a d nil f)
>
#24
Here is a solution (probably not the only one, nor the best) :
newLISP v.10.7.5 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h

> (select '(0 1 2 3 4) (difference (index true? '(0 1 2 3 4)) '(1 2)))
(0 3 4)
> ;; maybe clearer:
>
(let (lst '(0 1 2 3 4))
  (select lst (difference (index true? lst) '(1 2))))

(0 3 4)
>
#25
newLISP in the real world / Re: FUNCALL and GETDEF
October 27, 2018, 09:44:54 AM
Quote from: "cameyo"Hi newbert,

I have found these functions in an old article on Lisp (to define a function it use DE, maybe Portable Standard Lisp).

GETDEF gets the definition of a function.

Thanks for infos.

A Function in newLISP is not a "closure", so we can examine its content typing its name without parentheses :

> (define (double x) (+ x x))
(lambda (x) (+ x x))
> double
(lambda (x) (+ x x))

Thank you for info about GETDEF
#26
newLISP in the real world / Re: FUNCALL and GETDEF
October 26, 2018, 09:33:21 AM
I think there is no need to 'funcall' in newLisp, because variable name space and function name space are not separated as in Common Lisp, and maybe for other reasons, but I may be mistaken...



As for 'getdef', I can't give an answer because i don't know what is the use of this function in CL. Sorry !
#27
Quote from: "protozen"Hi All,



I'm curious if any new releases are on the horizon, and if there are future plans for newlisp in general. Love the language and programming in newlisp, I only wish it were a more general purpose platform / language, but I know it's not in the cards.


To my knowledge, I don't know any lisp-like scripting language which is more general purpose than Newlisp. And yet I have been trying some user-friendly Scheme implementations and a few Common Lisp. Even if they have indisputably many interesting and useful features, none of them are so concise, light and handy as Newlisp.

Frequently I can't help coming back to Newlisp, in spite of a personal preference for more functional programming, with tail call optimization, lexical scope, and so on, as in Scheme for instance. But moreover, we can sometimes apply all that in Newlisp too (tco with https://weblambdazero.blogspot.com/2010/07/advanced-recursion-in-newlisp.html">trampoline, lexical scope with http://www.newlisp.org/downloads/newlisp_manual.html#contexts">contexts, etc.)



;)
#28
newLISP in the real world / Re: Error in newLISP-GS
February 25, 2018, 09:51:11 AM
Me too !

When you described the phenomenon two days ago, I could reproduce it three times at least, but today not at all, strangely!



PS : the same error reappears when I come back once more on the tab 'untitled.lsp' after having done the opposite operation (cut in 'untitled.lsp' and paste again in the second tab).
#29
Quote from: "iNPRwANG"Why this forum's link not exists in newlisp's home page?


It exists in the http://www.newlisp.org/index.cgi?FAQ">About-page in "20.Where do I file bug reports?" and in the http://www.newlisp.org/index.cgi?Code_Contributions">Links-page in "Code collections and blogs" ... :)
#30
Just to inform: on my linux, I usually use this little module (a lightly modified 'runtk') :


;;;;
;;;; Module 'tk'
;;;; newLISP + tk  ('runtk' légèrement modifié - avril 2015)
;;;;
;;;; d'après runtk v 1.4 updated for 10.1 LM Nov 27th, 2009
;;;; original version by Fanda:
;;;;     http://www.intricatevisions.com/index.cgi?page=newlisp
;;;; Run programs written for newlisp-tk without without it
;;;; Only newLISP and a installation of Tcl/Tk is required.
;;;;
;;;; - faire (load "tk") en tête de script          
;;;; - écrire les commandes Tk à l'aide de la fonction (tk ...) qui accepte
;;;;   des chaîne de caractères comme arguments (arguments of 'tk' are strings)
;;;; - ajouter (tk-mainloop) en fin de script   (event loop)  
;;;;

;;; Installer les communications avec Tcl/Tk
(map set '(myin tcout) (pipe))
(map set '(tcin myout) (pipe))
(process "/usr/bin/wish" tcin tcout)

;;; La fonction 'tk' envoie des commandes à Tcl/Tk et retourne les erreurs éventuelles
(define (tk)
  (write-line myout (append "if { [catch { puts ["
              (apply string (args)) "] }] } { "
              [text] tk_messageBox -message $errorInfo; exit }
    [/text]))
   
    (let (str "")
        (while (starts-with (setq str (read-line myin)) "newLISP:")
            (eval-string ((length "newLISP: ") -1 str)))
        str))

(global 'tk)

;;; Sortir à la fermeture de la fenêtre principale
(tk "bind . <Destroy> {puts {(exit)}}")

;;; Boucle événementielle qui traite les requêtes entrantes de newLISP
(define (tk-mainloop)
    (while (read-line myin)
        (eval-string (current-line))))      
;;; NB : il faut ajouter cette fonction à la fin d'un script "newLISP-tk"


and this is a quick and succinct example of application (sorry for partial translation on the run):


(load "tk")

;;; Variables globales
(set 'x1 2 'y1 2)
(set 'x2 (+ x1 40) 'y2 (+ y1 40))
(set 'dx 8 'dy 0)
(set 'coor (string " " x1 " " y1 " " x2 " " y2 " "))
(set 'commut 0)

;;; Procédures gérant les événements
(define (arreter)
    ;; arrêter l'animation
    (setq commut 0))
   
(define (demarrer)
    ;; démarrer l'animation
    (++ commut)
    (if (= commut 1) (animer)))
   
(define (quitter)
    ;; quitter Tk et newLISP
    (tk "exit")
    (exit))
   
;;; Procédure principale
(define (animer)
    ;; déplacer la balle
    (setq x1 (+ x1 dx) y1 (+ y1 dy))
    (setq x2 (+ x1 40) y2 (+ y1 40))
    (setq coor (string " " x1 " " y1 " " x2 " " y2 " "))
    (if (> x1 360)
        (setq x1 360 dx 0 dy 8))
    (if (> y1 360)
        (setq y1 360 dx (- 8) dy 0))
    (if (< x1 2)
        (setq x1 2 dx 0 dy (- 8)))
    (if (< y1 2)
        (setq y1 2 dx 8 dy 0))
    (tk ".canevas coords " balle coor)
    (if (> commut 0)
        (tk "after 20 {puts (animer)}")))
       
;;;
;;; Programme principal
;;;

(tk "wm title . {Animation with newLISP & tk}        
     wm geometry . +200+200                        
     . configure -background DarkGrey")
                   
(tk "canvas .canevas -bg snow -height 400 -width 400        
     pack   .canevas -side left -padx 4 -pady 4")
     
;; Créer et afficher la forme (balle rouge)
(setq balle
    (tk ".canevas create oval " coor " -width 1 -fill red"))

;; Créer et placer les boutons de commande
(setq style
    (join '(" -width 10"                
            " -background RoyalBlue4"
            " -foreground white"
            " -activebackground RoyalBlue4"
            " -activeforeground orange"
            " -font {arial 10 bold}"))) ; 'style' des boutons
                   
(tk "button .demarrer -text Start -command {puts (demarrer)}" style)
(tk "button .arreter -text Stop  -command {puts (arreter) }"  style)
(tk "button .quitter -text Quit  -command {puts (quitter) }"  style)
(tk "pack .demarrer .arreter -padx 4 -pady 4")
(tk "pack .quitter -side bottom -padx 4 -pady 4")

;;;
;;; Scruter les requêtes entrantes de newLISP (boucle Tk)
;;;
(tk-mainloop)