A metatable can be defined like
local t = setmetatable({}, {
__tostring = function() return 'custom tostring behavior!' end
})
Here are the metamethods that you can define, and their behavior
arity?: func [p [word! path!] /local p2] [ | |
either word? p [ | |
preprocessor/func-arity? spec-of get :p | |
][ | |
; path format: obj1/obj2.../func/ref1/ref2... | |
; have to find a point where in that path a function starts | |
; i.e. p2: obj1/obj2.../func | |
; and the call itself is: func/ref1/ref2... | |
p2: as path! clear [] ; reuse the same block over and over again | |
until [ |
Macros(SPEL:-semantic-programming-enhancement-logic).md First of all, I advocate we call macros SPELs in order to get rid of the confusion when people come from other languages. This will also allow people who want to write tutorials about such a feature to easily(or more easily) google the word SPEL over macro. My recommendation of SPEL is not my own idea it comes from Conrad Barski: http://www.lisperati.com/no_macros.html
Shen, a dialect of lisp, will be what is used for spel examples. I will try to explain the syntax in order for readers of this wiki to be able to absorb the idea of spels. Come to this channel for questions, comments, approvals, disapprovals, or whatever else: https://gitter.im/red/red/lisp
We will begin(and end) by discussing two examples: max and thread.
In Shen, one defines a function at the repl like so...
NOTE: This gist uses the master branch of ClojureScript. Clone ClojureScript and from the checkout run
./script/bootstrap
and./script/uberjar
. This will producetarget/cljs.jar
which you can use to follow this guide.
As client applications become larger it becomes desirable to load only the code actually
required to run a particular logical screen. Previously ClojureScript :modules
compiler option
permitted such code splitting, but this feature only worked under :advanced
compilation
and users would still have to manage loading these splits. :modules
also required manual
#!/usr/bin/env boot | |
;; -*- mode: Clojure;-*- | |
(set-env! :dependencies '[[seesaw "1.4.5"]]) | |
(use 'seesaw.core) | |
(import '(javafx.scene.web WebView) | |
'(javafx.scene SceneBuilder) | |
'(javafx.scene.layout VBoxBuilder)) |
(ns clojr.core | |
(:require [instaparse.core :as insta]) | |
(:import (clojure.lang DynamicClassLoader))) | |
(import '[clojure.asm ClassWriter Type Opcodes] | |
'[clojure.asm.commons Method GeneratorAdapter]) | |
(def parser | |
(insta/parser | |
"prog = expr (<#'[\\n]+'> expr?)* |
# Hello, and welcome to makefile basics. | |
# | |
# You will learn why `make` is so great, and why, despite its "weird" syntax, | |
# it is actually a highly expressive, efficient, and powerful way to build | |
# programs. | |
# | |
# Once you're done here, go to | |
# http://www.gnu.org/software/make/manual/make.html | |
# to learn SOOOO much more. |
;; Transparent Functions | |
;; I was experimenting with transducers and wanted a way to understand how they worked. Transducer | |
;; code uses many nested functions in various locations with other nested functions defined as local | |
;; variables in scope. Typically after an anonymous Clojure function is defined you have no visibility | |
;; into the locals that were in scope when the function was defined, where the function came from, | |
;; or the code in the function. I defined a macro, tfn, that creates a transparent function. It's | |
;; a normal Clojure function with additional metadata including the function code and local | |
;; variable names and values. |
(ns cljsaudio.core | |
(:require [goog.net.XhrIo] | |
[cljs.core.async :as async :refer [<! >! chan close!]]) | |
(:require-macros [cljs.core.async.macros :refer [go]])) | |
(defn decode-audio-data | |
[context data] | |
(let [ch (chan)] | |
(.decodeAudioData context | |
data |
(ns n01se.externs-for-cljs | |
(:require [clojure.java.io :as io] | |
[cljs.compiler :as comp] | |
[cljs.analyzer :as ana])) | |
(defn read-file [file] | |
(let [eof (Object.)] | |
(with-open [stream (clojure.lang.LineNumberingPushbackReader. (io/reader file))] | |
(vec (take-while #(not= % eof) | |
(repeatedly #(read stream false eof))))))) |