Skip to content

Purl Language Reference

nanki edited this page Sep 13, 2010 · 2 revisions

Syntax.

Reverse polish notation separated by colon.

Literal.

Number
ex. 1, -1.5, 1E3

Operator
ex. mul, to.png

String
You can use “::” for single colon(“:”) in string literal.
ex. (Hello World), (http:://www.yahoo.com/)

Stack Operation.

op1 op2 swap op2 op1
swap two values on the stack.

op pop
pop the top element of the stack.

… n get result
get n-th element from the top of the stack.

… n pull result
bring the n-th element from the top of the stack to the top.

… n length slice result
bring the elements starting at n-th element to the top for length elements.

op dup op op
duplicate op.

… n reverse result
reverse the top n elements.

… m n stripe result
encode the top m × n elements into m × n matrix, transpose it and serialize it into n × m elements.

Conversion.

image to.png binary content-type
convert image to PNG stream.
image to.jpg binary content-type
convert image to JPEG stream.
image to.jpeg binary content-type
convert image to JPEG stream.
image to.gif binary content-type
convert image to GIF stream.
… n to.json binary content-type
pack last n elements to JSON array.

Image Operation.

id load image
load image from database.
image geom image width height
image x y width height crop image
image angle rotate image
image x1 y1 x2 y2 extend image
image1 image2 composite image
composite two images.

Effect Operation.

image radius blur image
image radius shadow image
image radius round image
image opacity opacify image
image radius dropshadow image
is swap:dup:2:pull:shadow:swap:composite

Resize Operation.

image width height resize image
resize image.

image width height resize.upto image
resize image preserving aspect ratio.

image width height resize.fitto image
resize image preserving aspect ratio.

Resize Macros.

image large image
image medium image
image small image

Arithmetic.

op1 op2 add result
op1 + op2

op1 op2 sub result
op1 – op2

op1 op2 mul result
op1 * op2

op1 op2 div result
op1 / op2

op1 op2 mod result
op1 mod op2

Cairo.

width height ctx context
prepare cairo surface and return context.

context ctx image
rendering to image.

context r g b rgb context
set current color.

context width linewidth context
set line-width.

context x y moveto context
move current point to x, y.

context x y lineto context
line to x, y.

context x y radius angle1 angle2 arc context
context x y radius angle1 angle2 arc.cw context
add arc to current path. begins at angle1(degree) to angle2(degree) clockwise.

context x y radius begin end arc.ccw context
add arc to current path. begins at angle1(degree) to angle2(degree) counterclockwise.

context x y radius circle context
add circle to current path.

context stroke context
draw current path.

context fill context
fill current path.

Macro.

( operators )
define macro.

Lmabda Operation.

… macro call result
expand macro.
… macro n times result
expand macro n times.
… macro n each result
expand macro after each of the top n elements.
… macro m n each.n result
expand macro after each group of m of the top n groups.
… macro m n each.stripe result
is equivalent to m n stripe macro m n each.n.

Arithmetic(Vector) – obsolete.

use Lambda module.


op1 op2 num add.2 result1 result2

op1 + num, op2 + num

op1 op2 num sub.2 result1 result2

op1 – num, op2 – num

op1 op2 num mul.2 result1 result2

op1 * num, op2 * num

op1 op2 num div.2 result1 result2

op1 / num, op2 / num

op1 op2 num mod.2 result1 result2

op1 mod num, op2 mod num