Lisp is a great language but it appears it not truely self modifying because macros can't be modified by other macros. (a . b) has (cons a b) as FullForm. 90minSchemetoCCompiler
The best idea I have come up with is to create a part of the code that exports to lisp code and a part that exports to Mathematica code. For example I could potentially prefix mathematica code with $ sign. Mathematica's editor is really nice. Another possibility is maybe using matics.net with the Mathematica FrontEnd. ClojureScript is another possibility. The goal is to essentially have the ideal of editor of Mathematica but with the code in an open source language. Mathematica Editor -> Lisp/JSON/XML -> JS/Java The problem is anything that involves pattern matching needs to call back to Mathematica/Mathics.net.
Python supports fractions, imaginary, infinity, -infinity, null, while JavaScript doesn't support fractions or imaginary numbers.
$Replace[Import["a.txt"],"a.txt"->"b.txt"] (Import "b.txt") Import/Require("test") $ReplaceAll[Import["c.txt"]],"c.txt"->"d.txt"] (ReplaceAll[Import["abc.txt"]],"abc.txt"->"test2.txt"]) ReplaceAll(`Import["test"]`,{"abc.txt":"test2.txt"}) $Replace[Import["test.txt"]] ()
(load "quicklisp.lisp") (quicklisp-quickstart:install) (load "C:/Users/a/quicklisp/setup.lisp") (json:encode-json '( ((foo . (1 2 3)) (bar . t) (baz . #\!)) "quux" 4/17 4.25)) (ql:quickload :cl-json) (with-input-from-string (s "[1, 2, 3]") (json:decode-json s) )
There is no FullForm of the following (defmacro add ( &rest args ) `(+ ,@args))
.
Intersection, FileNameJoin, StringDrop, Run new.zip other.zip
(setf (readtable-case *readtable*) :invert) (load 'init.lisp) (compile-mma) (load-mma) (|ReplaceAll| '(f 2 2) '(|Rule| (|Pattern| a (|BlankSequence|)) (f1 a) ) ) > (F1 ((F1 F) (F1 2) (F1 2))) (elt '(F1 ((F1 F) (F1 2) (F1 2)))) (|ReplaceAll| '(f 2) '(|Rule| (f (|Pattern| a (|Blank|))) (f1 a) ) ) > (f1 a) (|ReplaceAll| '(f a b) '(|Rule| (|Pattern| a (|Blank|))) (f 1 2) ))) > (f a b)
Mathematica & ExcelLisp Implementation Java
(defmacro IFF (condition &rest body) `(if ,condition (progn ,@body))) (IFF (> x 10) (print 0)) &rest &optional gensym IFF[condition_,body___]:=If[condition,body]; SetAttributes[IFF,HoldAll]; IFF[x<10,Print@0];
Mathematica | Lisp | |
HoldForm/quote |
|
|
ReleaseHold |
|
; Technically Hold doesn't exist but when fns are
; unevaluated they are a list with symbol as 1st elements
|
List |
|
|
Take |
|
|
Sequence | f[a, Sequence[b, c], d] | |
Prepend |
|
|
Append |
|
|
Join |
|
|
listp vectorp |
IntegerQ[1] | (numberp 1) (integerp 1) (rationalp 1) (realp 1) floatp complexp (listp '(1)) (vectorp #(1)) |
Pattern Matching | f[x, 1, 2] /. f[x_, y__] :> f[1, x, y] | (|ReplaceAll| '(f 1 2) '(|Rule| (f (|Pattern| a (|BlankSequence|))) (f1 a))) (ReplaceAll '(f x 1 2) ' ( (f (_ x) (__ y)) (f 1 x y) )) |
Apply | (coerce #(1 2 3) 'list) | |
Atoms | AtomQ | (cons '(1 . 2)) (not (atom '(1 . 2))) |
Drop | Drop[{a, b, c, d, e, f}, 2] (* Drop first 2 elements supports negative *) |
(select [email] :from [users] :where [= ["lower(name)"] (string-downcase customer)])
lisp FullForm(like mathematica's FullForm) would probably appear like the following but there is no FullForm for macros
(list '+ (vector '* 1))
The problem is that technically they won't work for output because VECTORs and LISTs are automatically converted to '() and #()
therefore there is now way to distinguish between
I don't like lisp b/c the folllowing returns
'(f '(+ 1))
> (f '(+ 1))
and notice how it doesn't print the 1st quote ' but it does in the second quote
Dotted Pair Notation
for example (rose . (violet)) equals (rose violet)
(rose . violet . buttercup) is invalid
(defun Depth (tree)
(if (atom tree)
0
(1+ (reduce #'max (mapcar #'max-depth tree)))))
(defun Flatten (structure) cond ((null structure) nil) ((atom structure) (list structure)) (t (mapcan #'flatten structure))))
(defun mkstr (&rest args) (with-output-to-string (s) (dolist (a args) (princ a s)))) (defun SymbolName (&rest args) (values (intern (apply #'mkstr args)))) (defun Symbol (a) (intern a))) (defun Symbol (a_String) (intern a)))
(apply #’(lambda (x y) (+ x y)) ’(1 2)) (mapcar #’(lambda (x) (+ x 10)) ’(1 2 3)) (mapcar #’+ ’(1 2 3) ’(10 100 1000)) (sort ’(1 4 2 5 6 7 3) #’<) (remove-if #’evenp ’(1 2 3 4 5 6 7)) (let ((s (make-string-input-stream "(1 2 3)"))) (read s)) OO Lisp (defun behave (animal) (funcall (get animal ’behavior))) (setf (get ’dog ’behavior) #’(lambda () (print 'wag-tail) (print 'bark)))
The following is a short docs of lisp http://jtra.cz/stuff/lisp/sclr/index.html