(ns expt2.core | |
(:require clojure.string clojure.pprint) | |
(:import [rx Observable subscriptions.Subscriptions])) | |
(defmacro pdump [x] | |
`(let [x# ~x] | |
(do (println "----------------") | |
(clojure.pprint/pprint '~x) | |
(println "~~>") | |
(clojure.pprint/pprint x#) |
Or, we can emulate the Reactive Framework's "GenerateWithTime". | |
Cold GenerateWithTime | |
Rx.Observable.GenerateWithTime = function( | |
initialState, // : State | |
condition, // : State -> bool | |
resultSelector, // : State -> Result | |
timeSelector, // : State -> int | |
iterate) // : State -> State |
(by @andrestaltz)
So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).
Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:
Rx.Observable.prototype.flatMapLatest(selector, [thisArg])
Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
Created from the plain text reference card on orgmode.org Download this file, and open it in Emacs org-mode!
(defpackage :io.github.rebcabin.temporary | |
(:use :common-lisp) | |
(:use :lisp-unit) | |
#+sbcl (:use :sb-ext)) | |
(in-package :io.github.rebcabin.temporary) | |
;;; I can definitely define a function with a gensymmed name: | |
(defmacro m1 () | |
(let ((g (gensym))) |
(* ::Package:: *) | |
(* ::Input:: *) | |
(*ClearAll[reset,shift];*) | |
(*reset[h_[As___, shift[k_, E_], Bs___]]:=*) | |
(*Block[{K=x\[Function]reset[h[As,x,Bs]]},*) | |
(*Print[<|"As"->{As},"h"->h,"k"->k,"E"->E,"Bs"->{Bs}|>];*) | |
(*reset[E/.{k->K}]];*) | |
(*reset[E_]:=E;*) |
This post also appears on lisper.in.
Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.
Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):
The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.
Module[{myNotebook, myCells, myStyles, myDemoIntegral, myDemoSolution, | |
myMathGroup, myItemGroup, myNumberedGroup, myCode, myProgramText, | |
myMeatyContentGroup, mySectionGroup, myDocumentGroup, | |
myFontFunction, myDefaultStyles, myNonDefaultStyles}, | |
myDemoIntegral = RowBox[{ | |
RowBox[{"\[Integral]", | |
RowBox[{"x", RowBox[{"\[DifferentialD]", "x"}]}]}], | |
"+", SqrtBox["z"]}]; | |
myDemoSolution = RowBox[{ | |
FractionBox[SuperscriptBox["x", "2"], "2"], |