User Tools

Site Tools


ch2_3_manage

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ch2_3_manage [2022/04/03 03:42] adminch2_3_manage [2024/05/04 11:15] (current) admin
Line 33: Line 33:
 </code> </code>
  
-Both actually accept any number of parameters. In ''APPLY'' the last argument must be list. The called function will check if it has the right number of paramteres. Here is example with ''+'', which also accepts any number of parameters:+Both actually accept any number of parameters. In ''APPLY'' the last argument must be list. The called function will check if it has the right number of parameters. Here is example with ''+'', which also accepts any number of parameters:
  
 <code lisp> <code lisp>
Line 45: Line 45:
 ''MAPCAR'', ''MAPLIST'', ''MAPCAN'', ''MAPCON'', ''MAPC'', ''MAPL'' ''MAPCAR'', ''MAPLIST'', ''MAPCAN'', ''MAPCON'', ''MAPC'', ''MAPL''
  
-These six similar functions apply given function to a list of arguments and produce a list of outputs. First argument must be function object, or symbol representing global function. Then can have any number of arguments, that must be list. Let's have some examples:+These six similar functions apply given function to a list of arguments and produce a list of outputs. First argument must be function object, or symbol representing global function. Then can have any number of arguments, that must be proper lists. Let's have some examples:
  
 <code lisp> <code lisp>
Line 52: Line 52:
 >(mapcar #'sqr '(1 2 3 4))   ; map to list of numbers >(mapcar #'sqr '(1 2 3 4))   ; map to list of numbers
 (1 4 9 16)                   ; get list of squares (1 4 9 16)                   ; get list of squares
->(mapcar '+ '(1 2 3) '(10 20 30))  ; can map multiple lists+>(mapcar #'+ '(1 2 3) '(10 20 30))  ; can map multiple lists
 (11 22 33)                           (11 22 33)                          
 </code> </code>
Line 61: Line 61:
  
   * ''MAPCAR'' and ''MAPLIST'' return freshly consed list of the results of the individual calls.   * ''MAPCAR'' and ''MAPLIST'' return freshly consed list of the results of the individual calls.
-  * ''MAPCON'' and ''MAPCAN'' make sense for applying functions that return lists. The final returned list is consed together from the individual outputs as a single list. This is done by modifying the individual outputs as with ''NCONC''.+  * ''MAPCAN'' and ''MAPCON'' make sense for applying functions that return lists. The final returned list is consed together from the individual outputs as a single list. This is done by modifying the individual outputs as with ''NCONC''.
   * ''MAPC'' and ''MAPL'' return just their first list argument, so they do not create any new conses. Only make sense for side effects of the applied function.    * ''MAPC'' and ''MAPL'' return just their first list argument, so they do not create any new conses. Only make sense for side effects of the applied function. 
  
Line 79: Line 79:
 </code> </code>
  
-  +The ''MAPCAN'' and ''MAPCON'' connect together the lists the same way as ''NCONC'', so they ignore (drop) dotted ends and can end up with cyclic list - if the last returned list is cyclic.
-... how we handle improper lists?+
  
 ''MACROEXPAND'' and ''MACROEXPAND-1'' ''MACROEXPAND'' and ''MACROEXPAND-1''
Line 115: Line 114:
 </code> </code>
  
-See also the section about macros in chapter 1.+See also [[ch1_6_macros|Macros]].
  
-''SET''+''SET'' 
  
-Primitive SET as function, evals both arguments, but first must be symbol. Only accepts 2 arguments. Normally use SETQ, but SET might be used in the rare case where we need variability in the symbol argument.+Primitive ''SET'' as function, expects exactly two arguments, first must be symbol. Normally use ''SETQ'', but ''SET'' might be helpful in the rare case where we need variability in the symbol argument. 
 + 
 +<code lisp> 
 +>(set 'a 12)                  ; is same as (SETQ a 12) 
 +12 
 +>(set (cadr '(a b)) 45)       ; first argument evals to symbol B 
 +45 
 +>b                            ; so B was set to 45 
 +45                      
 +</code>
  
 ''VALUES'' ''VALUES''
  
-Function that produces multiple values.+Some functions return multiple values, e.g. ''ROUND'', or ''MACROEXPAND'' above. Function ''VALUES'' allows us to return multiple values, constructed from the arguments supplied. Accepts any number of arguments, even no arguments. 
 + 
 +<code lisp> 
 +>(values 1 2) 
 +1                 ; returned as separate values 
 +
 +>(values) 
 +                  ; no return value                             
 +>(values 3) 
 +3                 ; trivial single value                         
 +</code> 
 + 
 +''NAME-PROCESS'' 
 + 
 +Cosmetic function for labeling processes as shown on the LabLISP window, accepts one or two arguments. First must be string - the desired name. Second argument is optional integer specifying the process number, if not supplied, the active process is renamed. This function can be only meaningfully used on the active running process, to give information about reason for waiting. Returns the string name. 
 + 
 +<code lisp> 
 +.. 
 +(move-motor 100)                ; non-blocking call to start moving 
 +(name-process "motor moving"  ; text will appear next to the active process 
 +(wait (motor-moves?))           ; waiting loop for end of physical operation 
 +..                       
 +</code> 
 + 
 +''KILL'' 
 + 
 +Function kills given process, needs one argument, the process number. Cannot be used on the active running process. Meaningful use is killing process stuck in an infinite loop. Returns ''NIL'' always. 
 + 
 +<code lisp> 
 +>(wait t)              ; infinite loop in process #0 
 +>(kill 0)              ; user entry, process #1 
 +p#01>NIL               ; return of the KILL function in process #1 
 +</code> 
 + 
 +''SELF-KILL''
  
-''NAME-PROCESS'' ''KILL''+This function kills the active running process, no arguments, returns ''NIL''. Although this might seem meaningless, this function is useful in mechanics for aborting script.
  
-these are unique LabLISP multi-process functions+The last three functions are unique for LabLISP multi-process mechanics. 
  
 See also the section 1.2 about multi-process behavior in LabLISP. See also the section 1.2 about multi-process behavior in LabLISP.
  
  
ch2_3_manage.1648978923.txt.gz · Last modified: 2022/04/03 03:42 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki