Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
def foo = {} // start with an empty map
foo.n = 42 // put a property
foo.z = 0
foo?n // does foo have property n?
foo.n // lookup property n
def bar = {|| => [print("Hello Cleveland")]}
bar() // prints Hello Cleveland
bar.|| // returns the list `[print("Hello Cleveland")]`
def foo = {} // start with an empty map
foo.n = 42 // put a property
foo.z = 0
foo?n // does foo have property n?
foo.n // lookup property n
def bar = {|| => [print("Hello Cleveland")]}
bar() // prints Hello Cleveland
bar.|| // returns `[print("Hello Cleveland")]`
\Main macro\
(qi::defmacro labels
[Defs Code] -> (LET ((qi::*tc* 'false))
(let F/Fs/Vis (map label-declares Defs)
F/Fs (map (/. X [(CAR X) (CADR X)]) F/FS/Vis)
Vis (map (/. X (CADDR X)) F/FS/Vis)
Defs2 (substitute F/Fs Defs)
Code2 (substitute F/Fs Code)
Defs3 (map lab-fixup Defs2)
Code3 [do [do|Visi] Code2]
Qi Core and ports
Functions that is in the core
QUIT DO MAKE-ARRAY AREF LISTP SQRT RANDOM ROUND EQUALP DEFSTRUCT STRING-EQUAL SYMBOL-NAME DELETE-FILE TAGBODY RETURN MAKUNBOUND SYMBOL-VALUE DEFVAR MAKE-HASH-TABLE GETHASH REMHASH FMAKUNBOUND HANDLER-CASE GO SYMBOL-FUNCTION READ-CHAR TERPRI PROGN SLEEP GENSYM PROG + PROGV FORCE-OUTPUT APPLY STRING BOUNDP DEFMACRO EVAL SETQ SETF CDR BLOCK ERROR LET* COERCE FORMAT NOT SYMBOLP LET * RETURN-FROM FUNCTION LAMBDA QUOTE LIST IF FUNCALL CONS EQ - DEFUN OR AND CONSP CAR
Can be combined ins some intelligent way
FLOATP REALP RATIONALP COMPLEXP WITH-OPEN-FILE MACRO-FUNCTION INTEGERP FBOUNDP ZEROP ATOM CHAR-EQUAL EQUAL STRINGP NUMBERP CHARACTERP EQL
can be expressed by core functions
\
This code using sugar functions to implement something more close
to lisp macros.
Example:
QI-SESSION
(32-) (defmacro plus
[X Y Z] -> [+ X Y Z])
>> macro-defined
(define format-row
C G [#\~ #\A |L] [X|J] -> [(format-AS human X)|(format-row C G L J)]
C G [#\~ #\S |L] [X|J] -> [(format-AS compu X)|(format-row C G L J)]
C G [#\~ #\C |L] [X|J] -> [(format-C human X)|(format-row C G L J)]
C G [#\~ #\@ #\C |L] [X|J] -> [(format-C compu X)|(format-row C G L
J)]
C G [#\~ #\P |L] [X|J] -> [(if (= X 1) [] [#\s])|(format-row C G L
J)]
C G [#\~ #\P |L] [X|J] -> [(if (= X 1) [] [#\s])|(format-row C G L
J)]
(ns #^{:doc "Lazy map, a map whose values are evaluated lazily.
This library depends on the \"New new\" feature in Clojure,
http://www.assembla.com/wiki/show/clojure/New_new
Based on Meikel Brandmeyer's gen-class implementation at
http://kotka.de/projects/clojure/lazy-map.html"
:author "Stuart Sierra"}
lazy-map)
var Log = {
elem: false,
write: function(text){
if (!this.elem)
this.elem = document.getElementById('log');
this.elem.innerHTML = text;
this.elem.style.left = (500 - this.elem.offsetWidth / 2) + 'px';
}
};
(defn filter-collecting [predicate collector & lists]
(lazy-seq
(loop [lists lists out []]
(if (empty? (first lists))
(reverse out)
(let [heads (map first lists)]
(if (apply predicate heads)
(recur (map rest lists) (cons (apply collector heads) out))
(recur (map rest lists) out)))))))
(defn filter-collecting [predicate collector & lists]
(lazy-seq
(loop [lists lists out []]
(if (empty? (first lists))
(reverse out)
(let [heads (map first lists)]
(if (apply predicate heads)
(recur (map rest lists) (cons (apply collector heads) out))
(recur (map rest lists) out)))))))