Code Select
> (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)
:)
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 MenuMy quesstion is:Quote from: "lyl"
Is there an universal method to determine whether a list can be evaluated or not?
> (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
>
Quote from: "lyl"
(setq a '(1 2 3)) ;; This list can not be evaled
Quote
(setq b '(1 a)) ;; This list can be evaled, (eval b) --> (2 3)
Quote
(setq c '(+ 1 2)) ;; This list can be evaled, (eval c) --> 3
My quesstion is:Quote
Is there an universal method to determine whether a list can be evaluated or not?
> (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
Quote from: "lyl"Here is a solution (probably not the only one, nor the best) :Quote from: "newBert"
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?
>
(let (lst '(a b c d nil f))
(select lst (difference (sequence 0 (- (length lst) 1)) '(1 2))))
(a d nil f)
>
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)
>
Hi newbert,Quote from: "cameyo"
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.
> (define (double x) (+ x x))
(lambda (x) (+ x x))
> double
(lambda (x) (+ x x))
Hi All,Quote from: "protozen"
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.
;;;;
;;;; 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"
(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)