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 "~#[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) (format T "10 ~@[ print nil level = ~D~]~%" *print-level* *print-length*) (format nil "11 ~@[ print nil level = ~D~]~%" *print-level* *print-length*) (print (format nil "12 ~@[ print nil level = ~D~]~%" *print-level* *print-length*) )

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

(format T "~%Cannot 200 call with argument~P" 0 ) ;;with arguments bizarre 0 pluriel (format T "~%Cannot 201 call with argument~P ~D" 0 0 ) ;; 0 pluriel?, 0 apres (format T "~%Cannot 202 call with ~D argument~P" 0 0 ) ;; 0 pluriel?, 0 avant
 * syntaxe plurielle des que différent de 1
 * (format T "Cannot 00 call with argument~P~%" ) NOK il manque arg

(format T "~%Cannot 203 call with argument~P" 1 ) ;; OK singulier non figuré (format T "~%Cannot 204 call with argument~P ~D" 1 1 ) ;; sing, 1 nommé apres (format T "~%Cannot 205 call with ~D argument~P" 1 1 ) ;; singulier, 1 nommé navant

(format T "~%Cannot 206 call with argument~P" 2 ) ;; OK plural, non figuré (format T "~%Cannot 206a call with argument~P ~D" 2 11 12) ;; pluriel, figuré, 2 apres (format T "~%Cannot 206b call with ~D argument~P" 2 10 11) ;; pluriel, figuré,  avant

(format T "~%Cannot 207 call with argument~P" -10 ) ;; négatif pluriel (format T "~%Cannot 207a call with argument~P ~S" -10 'suite... ) ;; négatif pluriel, suivant

(format T "~%Cannot 208 call with ~D argument~P" 1 1 ) (format T "~%Cannot 209 call with ~D argument~P~%" 3 3 ) (format T "~S : ~S a ~S argument~:P obligatoire~:P~%" 'module12 'func11 5 1);; 5 +extra ignored (format T "~S : ~S a ~S argument~:P obligatoire~:P" 'module13 'func01 1 1);; 1 +extra ignored

(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)
 * syntaxe combinée  Cannot call "DEPART" on 6
 * @ modifier: Only processes the clause [ if the format argument is T, otherwise skips it.

(format T "600 Listing of compilation of file ~A~%on ~A by ~A, version ~A~%" 'monfichier.txt '22.06.50 'Shimoun.Zoher '3.4.5.00 ) (format T "600a Listing de compilation du fichier ~A~%le ~A par ~A, version ~A~%" 'monfichier.txt '22.06.50 'Shimoun.Zoher '3.4.5.00 ) (format T "610 ~S from ~S: undefined label #~S#~%" 'at 'home '123AER45 2 ) (format T "~S de ~S : L'objet #Y~S n'a pas la syntaxe d'une «closure» compilée.~%" 611 'moi '56789 ) (format T "612 ~S de ~S : #~S= #~S# n'est pas permis~%" 'func33 'home 'af 'cz ) (format T "613 Image mémoire écrite dans ~A (~:D octet~:P)~%" 'fic1.txt 1024) (format T "613a Image mémoire écrite dans ~A (~:D octet~:P)~%" 'fic1.txt 0) (format T "613b Image mémoire écrite dans ~A (~:D octet~:P)~%" 'fic1.txt 1)
 * (format T "Cannot 05 call ~S on ~D~@[ or more~] argument~P ~%" "DEPART" 0 *print-level* )

(format T "614 Nouveau ~S [valeur ~D de ~D]~A~%" 'fic3.s 10 30 'f.zip)

(format T "~S ~S: invalid ~S lambda-list:~A~%" "Ch1" "Ch2" "Chaine" "minColumns,colInc,minPad,padChar" 1 2 3)
 * "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".