User:Wladek92/lisp

(print (+ 2 3) )
 * source: https://en.wikipedia.org/wiki/Format_(Common_Lisp)
 * ide  : https://www.jdoodle.com/execute-clisp-online/
 * meta character ~ (tilde)
 * ~[prefixParameters][modifiers]directiveType

(format t "~C~C" #\return #\linefeed) (format t "Hello world.~%")
 * passage a la ligne
 * the FORMAT control ~% prints a newline (!).

(format T "calcul simple: 10 + 20 = ~d~%" 30) (format T "binaire simple pour ~d: ~b~%" 13 13) (format T "padding gauche sur 8 char: ~8,'0b~%" 5)
 * Prints "1 + 2 = 3" to the standard output and returns ``NIL''.
 * format binaire
 * padding a gauche

(let ((number-of-digits 6)) (declare (type (integer 0 *) number-of-digits))  (format T "padd left variable 6 char: ~v,'0b~%" number-of-digits 5)) (defun print-as-hexadecimal (number-to-format number-of-digits) "Prints the NUMBER-TO-FORMAT in the hexadecimal system (radix 16),   left-padded with zeros to at least NUMBER-OF-DIGITS."  (declare (type number        number-to-format))  (declare (type (integer 0 *) number-of-digits))  (format T "hexa format using local defun print-as-hexadecimal: ~v,'0x~%" number-of-digits number-to-format))
 * V pour longueur variable passée dans parameterlist

(print-as-hexadecimal 12 2)

(format T "caractères A1 A2 Space B C D : ~C ~:C ~C ~C ~:c ~:@c" #\A #\A #\Space #\B #\C #\D )
 * caractères

(format T "~%hello ~S !" 'world) (format T "~%~S from ~S: token ~S after #: should contain no colon~%" 's1 's2 's3 's4)
 * newline
 * #: n'est pas un format

(format T "~S de ~S : la marque #~S= ne peut pas être définie deux fois~%" 's1 's2 's3 's4) (format T "~S de ~S : les objets imprimés avec # dans ~S ne peuvent pas y être relus~%"  's1 's2 's3 's4) (format T "~S : séquence d'octets non valide #x~C~C #x~C~C #x~C~C #x~C~C dans ~S~%"   'restart #\Z #\A #\F #\B #\C #\D  #\0 #\0 'lastArg #\B #\8 #\8) (format T "~S : erreur ~D : ~S~%" 'redo 230845 'expression_irrégulière )
 * l'argument devient majuscules (?...)

(format T "~S : le caractère #x~C~C~C~C~C~C~C~C dans la conversion ~S, n'est pas un caractère UTF-32~%" 'restart #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 'lastArg #\B #\8 #\8) (format T "~S utilisée par ~S ne permet pas qualifieurs ~:S : ~S~%"   'init 'helloWord 'chabada 'elston #\1 #\2) (format T "optional 1 argument~:P 0~%" 0) ;; 0 assimilé pluriel (format T "optional 1 argument~:P A~%" 'A) ;; non num assimilé pluriel (format T "optional 1 argument~:P 1 ok ~D~%" 1 200 300) (format T "optional 2 argument~:P 2 ok ~D ~D~%" 2 1000 2000 3000)  ;; accord pluriel (format T "optional 2 argument~:P 2 ok~%" 2) ;; accord pluriel
 * (format T "~S optional 0 argument~:P")  <- ERROR missing arg
 * (format T "optional 0 argument~:P") <- ERROR missing arg

(format T "~S argument~:P 1 ok ~D~%" 'opt 1 200 300) (format T "~S argument~:P 2 ok ~D ~D~%" 'opt 1000 2000 3000)  ;; accord pluriel

(format T "optional 2 argument~:P 0 0~%" 0 0) ;; 0 assimilé pluriel (format T "optional 1 argument~:P 1 0~%" 1) ;; singulier (format T "optional 2 argument~:P 2 0~%" 2 0) ;; pluriel ok (format T "optional plusieurs ~S~:P ~d ~S~%" 'argument 0 1);; optional plusieurs ARGUMENT 1 2 (format T "optional plusieurs ~S~:P ~d ~S~%" 'argument 1 2);; optional plusieurs ARGUMENT 1 2 (format T "optional plusieurs ~S~:P ~d ~S~%" 'argument 3 2)

(format T "~S optional argument~:P~%" 0) (format T "~S argument~:P optionnel~:P~%" 1) (format T "~S argument~:P optionnel~:P~%" 2)

(format T"~S argument~:P nécessaire~:P~%" 0 ) (format T"~S argument~:P nécessaire~:P~%" 1 ) (format T"~S argument~:P nécessaire~:P~%" 2 ) (format T"~S argument~:P nécessaire~:P ~S~%" 2 'fin )

(format T "~%~#[none selected~;one selected: ~a~;two selected: ~a and ~a~:;more selected: ~@{~a~^, ~}~]")
 * Directive conditionnelle
 * Prints "none selected".

(format T "~%~#[none selected~;one selected: ~a~;two selected: ~a and ~a~:;more selected: ~@{~a~^, ~}~]" 'bunny)
 * Prints "one selected: BUNNY".

(format T "~%~#[none selected~;one selected: ~a~;two selected: ~a and ~a~:;more selected: ~@{~a~^, ~}~]" 'bunny 'pigeon)
 * Prints "two selected: BUNNY and PIGEON".

(format T "~%~#[none selected~;one selected: ~a~;two selected: ~a and ~a~:;more selected: ~@{~a~^, ~}~]" 'bunny 'pigeon 'mouse)
 * Prints "more selected: BUNNY, PIGEON, MOUSE".

(format T "~%@ modifier for always sign: ~@b~%" 5) (format T "répétition de 5 char: ~5%" )
 * @ modifier: always with a number's sign
 * ...A CLARIFIER...
 * TYPE de directive

(setq *print-level* 102 *print-length* 5) (print (format nil "~@[ print level = ~D~]~%" *print-level* *print-length*) )

(setq *print-level* nil *print-length* 5) (print (format nil "~@[ print level = ~D~]~@[ print length = ~D~]~%" *print-level* *print-length*) )

(format T "Cannot 00 call with ~D argument~P~%" 1 1 ) (format T "Cannot 00 call with ~D argument~P~%" 3 3 )
 * syntaxe plurielle Cannot call "DEPART" on 6 or more arguments

(format T "Cannot 01 call with ~#[no arg~:;several args~]~%" ) (format T "Cannot 01 call with ~#[no arg~:;several args~]~%" 35503 "DEPART" ) (format T "Cannot 02 call on ~D~@[ or more~] argument~P~%" 3 3 ) (format T "Cannot 03 call on ~D~@[ or more~] argument~P~%" 0 *print-level* nil)
 * il faut 2 arg
 * @ modifier: Only processes the clause if the format argument is T, otherwise skips it.
 * 3 3
 * argument nil
 * 0 nil

(format T "Cannot 04 call ~S on ~D~@[ or more~] argument~P~%" "DEPART" 2 *print-level* 10) (format T "Cannot 05 call ~S on ~D~@[ or more~] argument~P ~%" "DEPART" 0 *print-level* ) (format T "~S ~S: invalid ~S lambda-list:~A~%" "Ch1" "Ch2" "Chaine" "minColumns,colInc,minPad,padChar" 1 2 3)
 * syntaxe combinée  Cannot call "DEPART" on 6
 * @ modifier: Only processes the clause [ if the format argument is T, otherwise skips it.
 * "Input a value to be used instead~@[ of ~S~]."
 * "The value of ~S should be ~:[of type ~S~;~:*~A~]."
 * "READ: ~@?"
 * "the syntax `,@form is invalid"
 * "the syntax `( ... . ,@form) is invalid"
 * "the syntax `,.form is invalid"
 * "the syntax `,@form is invalid"
 * "~S: unquotes may occur only in (...) or #(...) forms"
 * "~S: A file with name ~A does not exist"
 * "warning: %s %lu too large, using %lu instead"
 * "Input a value to be used instead~@[ of ~S~]."
 * "~S: Use of ~S implicitly applies FUNCTION.~@\n"
 * "The :@R format directive requires an integer in the range 1 - 4999, not ~S"
 * "Cannot call ~S on ~D~@[ or more~] argument~P"
 * "Function ~s~% was already defined~a~% with the signature~%~a~% it is being re-defined with a new signature~%~a"
 * A fourretout

(format T "string format: ~S~%" "Bonjour")

(format NIL "1 + 2 = ~d" 3)
 * Creates and returns a new string containing "1 + 2 = 3".

(with-output-to-string (output) (format output "1 + 2 = ~d" 3))
 * Creates and returns a new string containing "1 + 2 = 3".

(let ((output-string (make-array 0 :element-type 'character :adjustable T                      :fill-pointer 0)))  (declare (type string output-string))  (format output-string "2 + 2 = ~d" 4)  (the string output-string))
 * Appends to the dynamic string the string "1 + 2 = 3".

(let ((output-string (make-array 0 :element-type 'character :adjustable T                      :fill-pointer 0)))  (declare (type string output-string))  (format output-string "2 + 2 = ~d" 4)  (the string output-string))
 * Appends to the dynamic string the string "1 + 2 = 3".