# M

`*Msg`
  A global variable holding the last recently issued error message. See also `Error Handling`, `*Err` and `^`.

      : (+ 'A 2)
      !? (+ 'A 2)
      A -- Number expected
      ?
      :
      : *Msg
      -> "Number expected"

`+Mis`
  Prefix class to explicitly specify validation functions for `+relation`s. Expects a function that takes a value and an entity object, and returns `NIL` if everything is correct, or an error string. See also Database.

      (class +Ord +Entity)            # Order class
      (rel pos (+Mis +List +Joint)    # List of positions in that order
         ((Val Obj)
            (when (memq NIL Val)
               "There are empty positions" ) )
         ord (+Pos) )

`(macro prg) -> any`
  Substitues all `pat?` symbols in `prg` (using `fill`), and executes the result with `run`. Used occasionally to call functions which otherwise do not evaluate their arguments.

      : (de timerMessage (@N . @Prg)
         (setq @N (- @N))
         (macro
            (task @N 0 . @Prg) ) )
      -> timerMessage
      : (timerMessage 6000 (println 'Timer 6000))
      -> (-6000 0 (println 'Timer 6000))
      : (timerMessage 12000 (println 'Timer 12000))
      -> (-12000 0 (println 'Timer 12000))
      : (more *Run)
      (-12000 2616 (println 'Timer 12000))
      (-6000 2100 (println 'Timer 6000))
      -> NIL
      : Timer 6000
      Timer 12000
      ...

`(made ['lst1 ['lst2]]) -> lst`
  Initializes a new list value for the current `make` environment. All list elements already produced with `chain`, `link` and `yoke` are discarded, and `lst1` is used instead. Optionally, `lst2` can be specified as the new linkage cell, otherwise the last cell of `lst1` is used. When called without arguments, `made` does not modify the environment. In any case, the current list is returned.

      : (make
         (link 'a 'b 'c)         # Link three items
         (println (made))        # Print current list (a b c)
         (made (1 2 3))          # Discard it, start new with (1 2 3)
         (link 4) )              # Link 4
      (a b c)
      -> (1 2 3 4)

`(mail 'any 'cnt|lst 'sym1|lst2 'sym2|lst3 'sym3 'lst4 . prg)'`
  Sends an eMail via SMTP to a mail server at host `any`, port `cnt`. If the second argument is a list, it should be a structure `(user password . port)`, and "@bin/ssl" will be called to establish an encrypted connection. `sym1|lst2` should be the "from" address (or a cons pair of "reply-to" and "from"), `sym2|lst3` the "to" address(es), and `sym3` the subject. `lst4` is a list of attachments, each one specified by three elements for path, name and mime type. `prg` generates the mail body with `prEval`. See also `connect`.

      (mail "localhost" 25                               # Local mail server
         "a@bc.de"                                       # "From" address
         "abu@software-lab.de"                           # "To" address
         "Testmail"                                      # Subject
         (quote
            "img/go.png" "go.png" "image/png"            # First attachment
            "img/7fach.gif" "7fach.gif" "image/gif" )    # Second attachment
         "Hello,"                                        # First line
         NIL                                             # (empty line)
         (prinl (pack "This is mail #" (+ 3 4))) )       # Third line

`(make .. [(made 'lst ..)] .. [(link 'any ..)] ..) -> any`
  Initializes and executes a list-building process with the `made`, `chain`, `link` and `yoke` functions, and returns the resulting list. The final linkage cell is stored in the global variable `@@`. For efficiency, pointers to the head and the tail of the list are maintained internally.

      : (make (link 1) (link 2 3) (link 4))
      -> (1 2 3 4)
      : (make (made (1 2 3)) (link 4))
      -> (1 2 3 4)

`(map 'fun 'lst ..) -> lst`
  Applies `fun` to `lst` and all successive CDRs. When additional `lst` arguments are given, they are passed to `fun` in the same way. Returns the result of the last application. See also `mapc`, `maplist`, `mapcar`, `mapcon`, `mapcan` and `filter`.

      : (map println (1 2 3 4) '(A B C))
      (1 2 3 4) (A B C)
      (2 3 4) (B C)
      (3 4) (C)
      (4) NIL
      -> NIL

`map/3`
  Pilog predicate that returns a list and subsequent CDRs of that list, after applying the `get` algorithm to that object and the following arguments. Often used in database queries. See also `lst/3`.

      : (? (db nr +Ord 1 @Ord) (map @L @Ord pos))
       @Ord={B7} @L=({A1} {A2} {A3})
       @Ord={B7} @L=({A2} {A3})
       @Ord={B7} @L=({A3})
      -> NIL

`(mapc 'fun 'lst ..) -> any`
  Applies `fun` to each element of `lst`. When additional `lst` arguments are given, their elements are also passed to `fun`. Returns the result of the last application. See also `map`, `maplist`, `mapcar`, `mapcon`, `mapcan` and `filter`.

      : (mapc println (1 2 3 4) '(A B C))
      1 A
      2 B
      3 C
      4 NIL
      -> NIL

`(mapcan 'fun 'lst ..) -> lst`
  Applies `fun` to each element of `lst`. When additional `lst` arguments are given, their elements are also passed to `fun`. Returns a (destructively) concatenated list of all results. See also `map`, `mapc`, `maplist`, `mapcar`, `mapcon`, `filter`.

      : (mapcan reverse '((a b c) (d e f) (g h i)))
      -> (c b a f e d i h g)

`(mapcar 'fun 'lst ..) -> lst`
  Applies `fun` to each element of `lst`. When additional `lst` arguments are given, their elements are also passed to `fun`. Returns a list of all results. See also `map`, `mapc`, `maplist`, `mapcon`, `mapcan` and `filter`.

      : (mapcar + (1 2 3) (4 5 6))
      -> (5 7 9)
      : (mapcar + (1 2 3) 5)
      -> (6 7 8)
      : (mapcar '((X Y) (+ X (* Y Y))) (1 2 3 4) (5 6 7 8))
      -> (26 38 52 68)

`(mapcon 'fun 'lst ..) -> lst`
  Applies `fun` to `lst` and all successive CDRs. When additional `lst` arguments are given, they are passed to `fun` in the same way. Returns a (destructively) concatenated list of all results. See also `map`, `mapc`, `maplist`, `mapcar`, `mapcan` and `filter`.

      : (mapcon copy '(1 2 3 4 5))
      -> (1 2 3 4 5 2 3 4 5 3 4 5 4 5 5)

`(maplist 'fun 'lst ..) -> lst`
  Applies `fun` to `lst` and all successive CDRs. When additional `lst` arguments are given, they are passed to `fun` in the same way. Returns a list of all results. See also `map`, `mapc`, `mapcar`, `mapcon`, `mapcan` and `filter`.

      : (maplist cons (1 2 3) '(A B C))
      -> (((1 2 3) A B C) ((2 3) B C) ((3) C))

`(maps 'fun 'sym ['lst ..]) -> any`
  Applies `fun` to all properties of `sym`. When additional `lst` arguments are given, their elements are also passed to `fun`. Returns the result of the last application. Note that 'maps' should only be used when the property list is not modified by `fun`. Otherwise it is better to use a loop over the result of `getl`. See also `putl`.

      : (put 'X 'a 1)
      -> 1
      : (put 'X 'b 2)
      -> 2
      : (put 'X 'flg T)
      -> T
      : (getl 'X)
      -> (flg (2 . b) (1 . a))
      : (maps println 'X '(A B))
      flg A
      (2 . b) B
      (1 . a) NIL
      -> NIL

`(mark 'sym|0 ['NIL | 'T | '0]) -> flg`
  Tests, sets or resets a mark for `sym` in the database (for a second argument of `NIL`, `T` or `0`, respectively), and returns the old value. The marks are local to the current process (not stored in the database), and vanish when the process terminates. If the first argument is zero, all marks are cleared.

      : (pool "db")
      -> T
      : (mark '{1} T)      # Mark
      -> NIL
      : (mark '{1})        # Test
      -> T                 # -> marked
      : (mark '{1} 0)      # Unmark
      -> T
      : (mark '{1})        # Test
      -> NIL               # -> unmarked

`(match 'lst1 'lst2) -> flg`
  Takes `lst1` as a pattern to be matched against `lst2`, and returns `T` when successful. Atoms must be equal, and sublists must match recursively. Symbols in the pattern list with names starting with an at-mark "`@`" (see `pat?`) are taken as wildcards. They can match zero, one or more elements, and are bound to the corresponding data. See also `chop`, `split` and `fill`.

      : (match '(@A is @B) '(This is a test))
      -> T
      : @A
      -> (This)
      : @B
      -> (a test)
      : (match '(@X (d @Y) @Z) '((a b c) (d (e f) g) h i))
      -> T
      : @X
      -> ((a b c))
      : @Y
      -> ((e f) g)
      : @Z
      -> (h i)

`(max 'any1 'any2 ..) -> any`
`(max 'lst) -> any`
  Returns the largest of all `any` arguments, or of all elements in `lst`. See also min and Comparing.

      : (max 2 'a 'z 9)
      -> z
      : (max (5) (2 3) 'X)
      -> (5)
      : (max (2 4 1 3))
      -> 4

`(maxKey 'tree ['any1 ['any2]]) -> any`
  Returns the largest key in a database tree. If a minimal key `any1` and/or a maximal key `any2` is given, the largest key from that range is returned. See also `tree`, `leaf`, `minKey` and `genKey`.

      : (maxKey (tree 'nr '+Item))
      -> 7
      : (maxKey (tree 'nr '+Item) 3 5)
      -> 5

`(maxi 'fun 'lst ..) -> any`
  Applies `fun` to each element of `lst`. When additional `lst` arguments are given, their elements are also passed to `fun`. Returns that element from `lst` for which `fun` returned a maximal value (and stores the maximal value in the global variable `@@`). See also `mini` and `sort`.

      : (setq A 1  B 2  C 3)
      -> 3
      : (maxi val '(A B C))
      -> C
      : (maxi                          # Symbol with largest list value
         '((X)
            (and (pair (val X)) (size @)) )
         (all) )
      -> pico

`(member 'any 'lst) -> any`
  Returns the tail of `lst` that starts with `any` when `any` is a member of `lst`, otherwise `NIL`. See also `memq`, `assoc` and `idx`.

      : (member 3 (1 2 3 4 5 6))
      -> (3 4 5 6)
      : (member 9 (1 2 3 4 5 6))
      -> NIL
      : (member '(d e f) '((a b c) (d e f) (g h i)))
      -> ((d e f) (g h i))

`member/2`
  Pilog predicate that succeeds if the the first argument is a member of the list in the second argument. See also `equal/2` and `member`.

      :  (? (member @X (a b c)))
       @X=a
       @X=b
       @X=c
      -> NIL

`(memq 'any 'lst) -> any`
  Returns the tail of `lst` that starts with `any` when `any` is a member of `lst`, otherwise `NIL`. `==` is used for comparison (pointer equality). See also `member`, `mmeq`, `asoq`, `push1q`, `delq` and Comparing.

      : (memq 'c '(a b c d e f))
      -> (c d e f)
      : (memq (2) '((1) (2) (3)))
      -> NIL

`(meta 'obj|typ 'sym ['sym2|cnt ..]) -> any`
  Fetches a property value `any`, by searching the property lists of the classes and superclasses of `obj`, or the classes in `typ`, for the property key `sym`, and by applying the `get` algorithm to the following optional arguments. See also `var:`.

      : (setq A '(B))            # Be 'A' an object of class 'B'
      -> (B)
      : (put 'B 'a 123)
      -> 123
      : (meta 'A 'a)             # Fetch 'a' from 'B'
      -> 123

`(meth 'obj ['any ..]) -> any`
  This function is usually not called directly, but is used by `dm` as a template to initialize the `VAL` of message symbols. It searches for itself in the methods of `obj` and its classes and superclasses, and executes that method. An error `"Bad message"` is issued if the search is unsuccessful. See also OO Concepts, `method`, `send` and `try`.

      : meth
      -> 67283504    # Value of 'meth'
      : rel>
      -> 67283504    # Value of any message

`(method 'msg 'obj) -> fun`
  Returns the function body of the method that would be executed upon sending the message `msg` to the object `obj`. If the message cannot be located in `obj`, its classes and superclasses, `NIL` is returned. See also OO Concepts, `send`, `try`, `meth`, `super`, `extra`, `class`.

      : (method 'mis> '+Number)
      -> ((Val Obj) (and Val (not (num? Val)) "Numeric input expected"))

`(methods 'sym) -> lst`
  (Debug mode only) Returns a list of method specifications for the object or class `sym`, as they are inherited from `sym`'s classes and superclasses. See also OO Concepts, `dep`, `class` and `can`.

      : (more (methods '+Joint))
      (keep> . +Joint)
      (lose> . +Joint)
      (rel> . +Joint)
      (mis> . +Joint)
      (T . +Joint)
      (print> . +relation)
      (zap> . +relation)
      (del> . +relation)
      (put> . +relation)
      (has> . +relation)
      (ele> . +relation)

`(min 'any1 'any2 ..) -> any`
`(min 'lst) -> any`
  Returns the smallest of all `any` arguments, or of all elements in `lst`. See also max and Comparing.

      : (min 2 'a 'z 9)
      -> 2
      : (min (5) (2 3) 'X)
      -> X
      : (min (2 4 1 3))
      -> 1

`(minKey 'tree ['any1 ['any2]]) -> any`
  Returns the smallest key in a database tree. If a minimal key `any1` and/or a maximal key `any2` is given, the smallest key from that range is returned. See also `tree`, `leaf`, `maxKey` and `genKey`.

      : (minKey (tree 'nr '+Item))
      -> 1
      : (minKey (tree 'nr '+Item) 3 5)
      -> 3

`(mini 'fun 'lst ..) -> any`
  Applies `fun` to each element of `lst`. When additional `lst` arguments are given, their elements are also passed to `fun`. Returns that element from `lst` for which `fun` returned a minimal value (and stores the minimal value in the global variable `@@`). See also `maxi` and `sort`.

      : (setq A 1  B 2  C 3)
      -> 3
      : (mini val '(A B C))
      -> A

`(mix 'lst cnt|'any ..) -> lst`
  Builds a list from the elements of the argument `lst`, as specified by the following `cnt|'any` arguments. If such an argument is a positive number, the n'th element from `lst` is taken. If it is a negative number, the n'th CDR. Otherwise that argument is evaluated and the result is used.

      : (mix '(a b c d) 3 4 1 2)
      -> (c d a b)
      : (mix '(a b c d) -2 1)
      -> ((c d) a)
      : (mix '(a b c d) 1 'A 4 'D)
      -> (a A d D)

`(mmeq 'lst 'lst) -> any`
  Returns the tail of the second argument `lst` that starts with a member of the first argument `lst`, otherwise `NIL`. `==` is used for comparison (pointer equality). See also `member`, `memq`, `asoq` and `delq`.

      : (mmeq '(a b c) '(d e f))
      -> NIL
      : (mmeq '(a b c) '(d b x))
      -> (b x)

`(money 'num ['sym]) -> sym`
  Formats a number `num` into a digit string with two decimal places, according to the current `locale`. If an additional currency name is given, it is appended (separated by a space). See also `telStr`, `datStr` and `format`.

      : (money 123456789)
      -> "1,234,567.89"
      : (money 12345 "EUR")
      -> "123.45 EUR"
      : (locale "DE" "de")
      -> NIL
      : (money 123456789 "EUR")
      -> "1.234.567,89 EUR"

`(more 'lst ['fun]) -> flg`
`(more 'cls) -> any`
  (Debug mode only) Displays the elements of `lst` (first form), or the type and methods of `cls` (second form). `fun` defaults to `println`. In the second form, the method definitions of `cls` are pretty-printed with `pp`. After each step, `more` waits for a key, and terminates when ESC is pressed. In that case, `T` is returned, otherwise (when end of data is reached) `NIL`. See also `query` and `show`.

      : (more (all))                         # Display all internal symbols
      !
      $
      %
      &
      *
      -> T

      : (more (all) show)                    # 'show' all internal symbols
      ! 27131845007
         doc "@doc/ref_.html"
         *Dbg ((1458 "@src/flow.l" llvm pico))
      $ 27131845049
         doc "@doc/ref_.html"
         *Dbg ((1508 "@src/flow.l" llvm pico))
      % -27131839417
         doc "@doc/ref_.html"
         *Dbg ((1245 "@src/big.l" llvm pico))
      & -27131839537
         doc "@doc/ref_.html"
         *Dbg ((1380 "@src/big.l" llvm pico))
      * -27131839339
         doc "@doc/ref_.html"
         *Dbg ((1174 "@src/big.l" llvm pico))
      ...

      : (more '+Link)                        # Display a class
      (+relation)
      (dm mis> (Val Obj)
         (and
            Val
            (nor (isa (: type) Val) ("canQuery" Val))
            "Type error" ) )
      (dm T (Var Lst)
         (unless (=: type (car Lst)) (quit "No Link" Var))
         (super Var) )
      -> NIL

`(msg 'any ['any ..]) -> any`
  Prints `any` with `print`, followed by all `any` arguments (printed with `prin`) and a newline, to standard error. The first `any` argument is returned.

      : (msg (1 a 2 b 3 c) " is a mixed " "list")
      (1 a 2 b 3 c) is a mixed list
      -> (1 a 2 b 3 c)