*Uni
- A global variable holding an
idx
tree, with all unique data that were collected with the comma (,
)
read-macro. Typically used for localization. Setting *Uni
to
T
disables this mechanism. See also Read-Macros
and locale
.
: (off *Uni) # Clear
-> NIL
: ,"abc" # Collect a transient symbol
-> "abc"
: ,(1 2 3) # Collect a list
-> (1 2 3)
: *Uni
-> ("abc" NIL (1 2 3))
+UB
- Prefix class for
+Aux
to maintain
an UB-Tree index instead of the direct values. This allows efficient range
access to multi-dimensional data. Only positive numeric keys are supported. See
also ubIter
and Database.
(class +Pos +Entity)
(rel x (+UB +Aux +Ref +Number) (y z))
(rel y (+Number))
(rel z (+Number))
: (scan (tree 'x '+Pos))
(288362200753438306 . {13}) {13}
(348187139486943716 . {16}) {16}
(605261596962573238 . {11}) {11}
(638523558602802506 . {7}) {7} # UBKEY of (453062 450921 613956)
(654697989157410399 . {12}) {12}
...
: (show '{7})
{7} (+Pos)
x 453062
y 450921
z 613956
-> {7}
# Discrete queries work the same way as without the +UB prefix
: (db 'x '+Pos 453062 'y 450921 'z 613956)
-> {7}
: (aux 'x '+Pos 453062 450921 613956)
-> {7}
: (? (db x +Pos (453062 450921 613956) @Pos))
@Pos={7}
-> NIL
# Range queries work efficiently with 'collect'. Note that though also Pilog
queries can handle UB-trees, they may do so sub-optimally for certain ranges.
: (collect 'x '+Pos (200000 200000 200000) (899999 899999 899999))
-> ({7} {14} {17} {15})
(u) -> T
- (Debug mode only) Removes
!
all
breakpoints in all subexpressions of the current breakpoint. Typically used when
single-stepping a function or method with debug
. See also d
and unbug
.
! (u) # Unbug subexpression(s) at breakpoint
-> T
(ubIter 'tree 'dim 'fun 'lst1 'lst2)
- Efficiently iterates through a database
+UB
tree, by applying fun
to all
values. dim
is the number of the key dimensions, lst1
and lst2
specify a range of keys. collect
uses ubIter
internally
for UB-tree queries. See also iter
.
: (ubIter (tree 'x '+Pos) 3 show (200000 200000 200000) (899999 899999 899999))
{7} (+Pos)
z 613956
y 450921
x 453062
{14} (+Pos)
z 771372
y 262217
x 862358
{17} (+Pos)
z 676836
y 529576
x 398229
{15} (+Pos)
z 889332
y 691799
x 265381
-> NIL
(udp 'any1 'any2 'any3) -> any
(udp 'cnt) -> any
- Simple unidirectional sending/receiving of UDP packets. In the first form,
any3
is sent to a UDP server listening at host any1
,
port any2
. In the second form, one item is received from a UDP
socket cnt
, established with port
. See also listen
and connect
.
# First session
: (port T 6666)
-> 3
: (udp 3) # Receive a datagram
# Second session (on the same machine)
: (udp "localhost" 6666 '(a b c))
-> (a b c)
# First session
-> (a b c)
(ultimo 'y 'm) -> cnt
- Returns the
date
of the last day
of the month m
in the year y
. See also day
and week
.
: (date (ultimo 2007 1))
-> (2007 1 31)
: (date (ultimo 2007 2))
-> (2007 2 28)
: (date (ultimo 2004 2))
-> (2004 2 29)
: (date (ultimo 2000 2))
-> (2000 2 29)
: (date (ultimo 1900 2))
-> (1900 2 28)
(unbug 'sym) -> T
(unbug 'sym 'cls) -> T
(unbug '(sym . cls)) -> T
- (Debug mode only) Removes all
!
breakpoints in the function or method body of sym, as inserted with debug
or d
, or directly with vi
. See also u
.
: (pp 'tst)
(de tst (N)
(! println (+ 3 N)) ) # 'tst' has a breakpoint '!'
-> tst
: (unbug 'tst) # Unbug it
-> T
: (pp 'tst) # Restore
(de tst (N)
(println (+ 3 N)) )
(undef 'sym) -> fun
(undef 'sym 'cls) -> fun
(undef '(sym . cls)) -> fun
- Undefines the function or method
sym
. Returns the previous
definition. See also de
, dm
, def
and redef
.
: (de hello () "Hello world!")
-> hello
: hello
-> (NIL "Hello world!")
: (undef 'hello)
-> (NIL "Hello world!")
: hello
-> NIL
(unify 'any) -> lst
(unify 'cnt) -> cnt
- The first form unifies
any
with the current Pilog environment at the current level and with a
value of NIL
, and returns the new environment or NIL
if not successful. The second form unifies all variables at the given level with
the current one. See also prove
and
->
.
: (? (^ @A (unify '(@B @C))))
@A=(((NIL . @C) 0 . @C) ((NIL . @B) 0 . @B) T)
(uniq 'lst) -> lst
- Returns a unique list, by eliminating all duplicate elements from
lst
. See also Comparing, sort
and group
.
: (uniq (2 4 6 1 2 3 4 5 6 1 3 5))
-> (2 4 6 1 3 5)
uniq/2
- Pilog predicate that succeeds if the second
argument is not yet stored in the first argument's index structure.
idx
is used internally storing for the values
and checking for uniqueness. See also member/2
.
: (let U NIL
(? (lst @X (a b c b c d)) (uniq U @X)) )
@X=a
@X=b
@X=c
@X=d
-> NIL
: (solve '((^ @B (box)) (lst @X (a b c b c d)) (uniq @B @X)) @X)
-> (a b c d)
(unless 'any . prg) -> any
- Conditional execution: When the condition
any
evaluates to
non-NIL
, NIL
is returned. Otherwise prg
is executed and the result returned. See also when
, ifn
, nor
, nand
and nond
.
: (unless (= 3 3) (println 'Strange 'result))
-> NIL
: (unless (= 3 4) (println 'Strange 'result))
Strange result
-> result
(until 'any . prg) -> any
- Conditional loop: While the condition
any
evaluates to
NIL
, prg
is repeatedly executed. If prg
is never executed, NIL
is returned. Otherwise the result of
prg
is returned. See also while
, for
, loop
and do
.
: (until (=T (setq N (read)))
(println 'square (* N N)) )
4
square 16
9
square 81
T
-> 81
(untrace 'sym) -> sym
(untrace 'sym 'cls) -> sym
(untrace '(sym . cls)) -> sym
- (Debug mode only) Removes the
$
trace
function call at the beginning of the function or method body of
sym
, so that no more trace information will be printed before and
after execution. Built-in functions (SUBRs) are automatically converted to their
original form (see subr
). See also
trace
and traceAll
.
: (trace '+) # Trace the '+' function
-> +
: +
-> (@ ($ + @ (pass $385455126))) # Modified for tracing
: (untrace '+) # Untrace '+'
-> +
: +
-> 67319120 # Back to original form
(up [cnt] sym ['val]) -> any
- Looks up (or modifies) the
cnt
'th previously saved value of
sym
in the corresponding enclosing environment. If cnt
is not given, 1 is used. It is allowed to omit the sym
argument,
then the corresponding expression (function or method call) is returned. See
also eval
, run
, trail
and env
.
: (let N 1 ((quote (N) (println N (up N))) 2))
2 1
-> 1
: (let N 1 ((quote (N) (println N (up N) (up N 7))) 2) N)
2 1 7
-> 7
: (de foo (N)
(println (up))
(inc N) )
-> foo
: (foo 7)
(foo 7)
-> 8
(upd sym ..) -> lst
- Synchronizes the internal state of all passed (external) symbols by passing
them to
wipe
. upd
is the
standard function passed to commit
during database transactions
.
(commit 'upd) # Commit changes, informing all sister processes
(upp? 'any) -> sym | NIL
- Returns
any
when the argument is a string (symbol) that starts
with an uppercase character. See also uppc
and low?
: (upp? "A")
-> "A"
: (upp? "a")
-> NIL
: (upp? 123)
-> NIL
: (upp? ".")
-> NIL
(uppc 'any) -> any
- Upper case conversion: If
any
is not a symbol, it is returned
as it is. Otherwise, a new transient symbol with all characters of
any
, converted to upper case, is returned. See also lowc
, fold
and upp?
.
: (uppc 123)
-> 123
: (uppc "abc")
-> "ABC"
: (uppc 'car)
-> "CAR"
(use sym . prg) -> any
(use (sym ..) . prg) -> any
- Defines local variables. The value of the symbol
sym
- or the
values of the symbols sym
in the list of the second form - are
saved, prg
is executed, then the symbols are restored to their
original values. During execution of prg
, the values of the symbols
can be temporarily modified. The return value is the result of prg
.
See also bind
, job
and let
.
: (setq X 123 Y 456)
-> 456
: (use (X Y) (setq X 3 Y 4) (* X Y))
-> 12
: X
-> 123
: Y
-> 456
(useKey 'sym 'cls ['hook]) -> num
- Generates or reuses a key for a database tree, by randomly trying to locate
a free number. See also
genKey
.
: (maxKey (tree 'nr '+Item))
-> 8
: (useKey 'nr '+Item)
-> 12
(usec ['flg]) -> num
- Returns a number of microseconds. If
flg
is
non-NIL
, the microsecond fraction of the last call to time
is returned, otherwise the number of
microseconds since interpreter startup. See also date
.
: (usec)
-> 1154702479219050
: (list (date (date)) (time (time T)) (usec T))
-> ((2013 1 4) (10 12 39) 483321)