You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
apples='33 tasty apples'oranges='6 juicy oranges'output="I had $apples and $oranges"# note double quotesoutput="I paid \$34 for them"# uninterpolated dollar signoutput='I paid $34 for them'# or, alternatively, single quotes
Requiring another file
use:base# .zr is assumeduse:base,:extensions,:extensions-optional# if no file is found, but folder is present, loads all .zr files from the folderuse-all# loads all .zr files in current folderuse"core/base.zr"# direct filename
Variable assigning
a=ba,b=b,a# swappinga,b,c=d,e,f# mass assignmentfirst,second,third=a# list decomposed into elementsa=:first,:second,:third# a is a list
Hashes
hash=field: 'a',other-field: 'b',yet-another: 'c'# :field, :other-field and :yet-another are symbolsvar=:new-varhash << ($var: 'd')# hash :new-var == 'd'hash.$var ='d'# alternativehash.field# => a
use:animals-core#=> loads animals-core.zr, no namespace defineduse:pigs,Pig#=> define Pig namespace for functions in pigs.zrPig:oink#=> a function called which is defined in pigs.zrfoink'Oink!'poink#=> local implementationpPig:oink#=> external implementation
Return values
faddx,yx + y#=> last statement is returned by defaultfdividex,yreturnNANify == 0#=> preemptive returnx / yf(complex,numeric).addx,yy-real,y-imaginary=complex?y ? (y.real,y.imaginary) : (y,0)
*complexx.real + y-real,x.imaginary + y-imaginary#=> struct is returned
fdo-stuffarg1,arg2do-more-complex-stuffarg1,arg2,5# Basic function declarationfinline-function='Hello world'# one-line versionfzircon?arg1,(arg2,'zircon')=trueifarg1 == arg2# default parameters# Warning: for every struct defined, struct-name? is reserved.# Types of functions are normally inferred. Manual type declaration:fcomplex.real-partxx.realf(complex,numeric).real-part-equal?x,yx.real==y# Full type signaturef(complex,numeric -> boolean).imaginary-part-equal?x,yx.imaginary == y
Switch
a=caseb2 ? 'moo'3 ? 'frank'4 ? 'ziegenbock'
:else ? 'something else'# How case is definedfcasevalue,statementsstatements >> (f_s,v=break-withv.1if(v.0 == b || v.0 == :else))fany:x ? any:yx,y