2 Core Library
Art comes with a library of objects, coordinates, contexts, rewriters, and realizers which will be generally useful across various languages.
2.1 General Forms
syntax
(define-art id art-statement ...)
syntax
(@ [coordinate ...] art-statement...)
Intuitively, run the given statements at the given coordinates.
This is accomplished by independently merging the given coordinates into the identity context of each statement, then running the statements.
syntax
(draw-realizer [width height])
Draw an artwork. See Extending the Draw Realizer.
syntax
(number value)
A number.
> (realize (draw-realizer [50 50]) (number 42))
syntax
(numbers number ...)
a series of indexed numbers, shorthand for (ix-- (number ...) (number ...) (number ...)).
> (realize (draw-realizer [300 50]) (seq (numbers 42 1.618 57 3.14)))
syntax
(symbol value)
A symbol.
> (realize (draw-realizer [50 50]) (symbol hello))
syntax
(hole)
Represents a place where an object might go.
> (realize (draw-realizer [50 50]) (hole))
syntax
(fill-holes id)
A rewriter which maps all holes within its coordinates to all objects of type id which surround the hole. The inserted objects will have their own identities and the same coordinates as the former hole.
> (define-art square1 (seq (ix-- (numbers 1 4/3) (numbers 5/3 2)))) > (realize (draw-realizer [200 200]) square1) > (define-art mystery-square (seq (ix-- (ix-- (hole) (symbol square)) (ix-- (symbol back) (hole))))) > (realize (draw-realizer [200 200]) mystery-square)
> (realize (draw-realizer [200 200]) (seq square1 mystery-square (run-apl (mix *ctxt*)) (fill-holes number))) for: expected a sequence for expr, got something else: #<syn
tax:/home/root/user/.local/share/racket/8.12/pkgs/art-lib/pr
ivate/core.rkt:354:65 ((number 1) (number 4/3) (number 5/3)
(number 2) (hole) (symbol square) (symbol back) (hole))>
2.2 Coordinates
2.2.1 Interval
Intervals are coordinates with a start and an end. Interval within? is the intuitive definition of closed interval containment. Merging intervals offsets the right interval by the start of the left interval. Intervals are used in timelines and music.
syntax
(interval (start number) (end number))
An interval coordinate.
> (realize (draw-realizer [800 100]) (timeline (@ [(interval (start 2) (end 5))] (symbol hello)) (@ [(interval (start 5) (end 10))] (symbol world))))
syntax
(i@ [number number] body ...)
Shorthand for an interval.
> (realize (draw-realizer [800 100]) (timeline (i@ [2 5] (symbol hello)) (i@ [5 10] (symbol world))))
syntax
(-- number [number art-expr ...] ...)
syntax
(-- [number art-expr ...] ...)
Create a series of consecutive intervals of the given lengths, running the statements within those intervals. The first number determines the start of the first interval. If it is not provided then it is 0.
syntax
(translate number)
syntax
(dilate number)
Dilate all intervals by the given factor. The distance between the target interval and the start of the dilation is also dilated (which is the intuitive behavior).
> (realize (draw-realizer [800 100]) (timeline (-- 1 [1 (symbol hello)] [1 (symbol world)]) (dilate 4) (-- 1 [1 (symbol hello-)] [1 (symbol world-)]))) for: expected a sequence for expr, got something else: #<syn
tax:/home/root/user/.local/share/racket/8.12/pkgs/art-lib/pr
ivate/core.rkt:354:65 ((i@ (4 8) (symbol hello)) (i@ (8 12)
(symbol world)))>
> (realize (draw-realizer [800 100]) (timeline (-- 1 [1 (symbol hello)] [1 (symbol world)]) (i@ 1 (dilate 4)) (-- 1 [1 (symbol hello-)] [1 (symbol world-)]))) for: expected a sequence for expr, got something else: #<syn
tax:/home/root/user/.local/share/racket/8.12/pkgs/art-lib/pr
ivate/core.rkt:354:65 ((i@ (1 5) (symbol hello)) (i@ (5 9)
(symbol world)))>
syntax
(loop number art-expr ...)
syntax
Represents a loop of the specified duration. The loop must be expanded within an interval and will be expanded to consecutive intervals containing the given expressions. It will be repeated as many times as fits cleanly into the surrounding interval. TODO explain rewriters inside loops
> (realize (draw-realizer [800 100]) (timeline (i@ [0 30] (loop 10 (-- 2 [3 (symbol hello)] [5 (symbol world)]))) (expand-loop)))
syntax
(rhythm number ...)
Represents a series of consecutive intervals of the given durations. A sequence and a rhythm can be converted to a concrete series of intervals via apply-rhythm. A type that is in context over the entire span of the rhythm can be converted to a concrtete series of intervals via rhythm->holes and fill->holes.
syntax
(uniform-rhythm number)
A rewriter that creates a rhythm subdividing its interval into equal parts of the provided length.
syntax
> (define-art world-domination-plan (timeline (i@ [0 3.5] (symbol Cat)) (i@ [0 2.5] (symbol Hello_____World)) (i@ [2 4] (symbol ___!)) (rhythm 1 1.25 0.75 0.5))) ; Better decipher this, before it’s too late! > (realize (draw-realizer [800 100]) world-domination-plan) ; We’ve had a breakthrough! We’ve almost got it...
> (realize (draw-realizer [800 100]) world-domination-plan (rewrite-in-timeline (rhythm->holes))) ; Oh no, it’s all meowver— - *HISSSSS* [END TRANSMISSION]
> (realize (draw-realizer [800 100]) world-domination-plan (rewrite-in-timeline (rhythm->holes) (fill-holes symbol)))
2.2.2 Sets
Sets are coordinates with a set of identifiers. Set within? and merge can either be superset and union, or subset and intersection. Subset sets are used for voices in music. Superset sets are used for lexical scope.
2.2.3 Indices
Indices are coordinates with a list of numbers. An index with n-numbers is called an n-dimensional index. Index within? is = and merge is append. Indices are used in sequences.
syntax
(index expr ...)
syntax
(ix@ [number ...] expr ...)
syntax
(ix-- expr ...)
2.2.4 Name
Names are coordinates with a list of identifiers. Name within? is prefix match and merge is append. Names are used in namespaces.
syntax
(name id ...)
syntax
(name@ (id ...) expr ...)
2.3 Contexts
2.3.1 Timeline
Timelines are contexts equipped with an interval coordinate.
syntax
(timeline expr ...)
syntax
(rewrite-in-timeline expr ...)
> (define-art layer3 (timeline (i@ [0 1] (number 42)) (i@ [2 3] (number 42)))) > (define-art layer2 (timeline (i@ [0 3] layer3) (i@ [6 9] layer3))) > (define-art layer1 (timeline (i@ [0 9] layer2) (i@ [18 27] layer2))) > (realize (draw-realizer [800 50]) layer1)
2.3.2 Sequence
Sequences are contexts equipped with an index coordinate.
syntax
(seq expr ...)
syntax
(rewrite-in-seq expr ...)
> (define-art the-seqs (ix-- (seq (ix-- (number 42) (number 42) (symbol X))) (seq (ix-- (number 42) (symbol X) (number 42))) (seq (ix-- (symbol X) (number 42) (number 42))))) > (realize (draw-realizer [500 50]) (seq the-seqs)) > (realize (draw-realizer [200 100]) (seq the-seqs (run-apl (mix *ctxt*)))) for: expected a sequence for expr, got something else: #<syn
tax:/home/root/user/.local/share/racket/8.12/pkgs/art-lib/pr
ivate/core.rkt:354:65 ((number 42) (number 42) (symbol X)
(number 42) (symbol X) (number 42) (symbol X) (number 42)
(number 42))>
syntax
(! ix)
syntax
(seq-ref)
syntax
(ix-loop expr ...)
syntax
(expand-ix-loop expr ...)
2.3.3 Namespace
Namespaces are contexts equipped with a name coordinate.
syntax
(namespace expr ...)
syntax
(rewrite-in-namespace expr ...)
> (realize (draw-realizer [800 50]) (namespace (name@ the-answer (number 42)) (name@ the-questions (namespace (name@ q1 (symbol |What is 4 + 2?|)) (name@ q2 (symbol Life))))))
syntax
(ref id)
syntax
Namespaces have some convenient interactions with art definition forms.
syntax
Reify identifiers bound using define-art into a namespace art. FIXME jagen this has 500 possible semantics and needs clarification.
> (realize (draw-realizer [800 50]) (namespace (reify-art-definitions)))
syntax
Compile all names in a namespace to racket art definitions, and provide them.
> (module test racket (require art art/namespace) (realize (namespace-provide-realizer) (name@ the-answer (number 42)) (name@ the-questions (namespace (name@ q1 (symbol |What is 4 + 2?|)) (name@ q2 (symbol Life)))))) > (require 'test) > (realize (draw-realizer [50 50]) the-answer)
A cool technique is possible using the two forms above- running a transform over an entire module before exporting.
> (module test2 racket (require art art/namespace art/sequence art/sequence/ravel) ; <Foo, Bar> (define-art thing1 (seq (ix-- (symbol Foo) (symbol Bar)))) ; <1, 2, 3> (define-art thing2 (seq (numbers 1 2 3))) ; provide the definitions, but reversed and repeated 3 times, for demo purposes. (realize (namespace-provide-realizer) (reify-art-definitions) (rewrite-in-seq (run-apl (replicate (lit 3) (enclose (apl:reverse *ctxt*))))))) for: expected a sequence for expr, got something else: #<syn
tax:/home/root/user/.local/share/racket/8.12/pkgs/art-lib/pr
ivate/core.rkt:354:65 ((seq (symbol Bar) (symbol Foo)) (seq
(symbol Bar) (symbol Foo)) (seq (symbol Bar) (symbol Foo)))>
> (require 'test2) require: unknown module
module name: 'test2
> (realize (draw-realizer [800 50]) thing1 thing2) eval:36:0: run-art-expr: unknown var: #<syntax:eval:36:0
thing1>
in: thing1