Tutorial by Examples

We can repeat an action some number of times using repeat. CL-USER> (loop repeat 10 do (format t "Hello!~%")) Hello! Hello! Hello! Hello! Hello! Hello! Hello! Hello! Hello! Hello! NIL CL-USER> (loop repeat 10 collect (random 50)) (28 46 44 31 5 33 43 35 37 4)
(loop for i in '(one two three four five six) do (print i)) (loop for i in '(one two three four five six) by #'cddr do (print i)) ;prints ONE THREE FIVE (loop for i on '(a b c d e f g) do (print (length i))) ;prints 7 6 5 4 3 2 1 (loop for i on '(a b c d e f g) by #'cddr ...
(defvar *ht* (make-hash-table)) (loop for (sym num) on '(one 1 two 2 three 3 four 4 five 5 six 6 seven 7 eight 8 nine 9 ten 10) by #'cddr do (setf (gethash sym *ht*) num)) (loop for k being each hash-key of *ht* do (print k)) ; iterate over the keys (loop for k ...
Simple LOOP form without special keywords: (loop forms...) To break out of the loop we can use (return <return value>) ` Some examples: (loop (format t "Hello~%")) ; prints "Hello" forever (loop (print (eval (read)))) ; your very own REPL (loop (let ((r (read))) ...
(loop for s being the symbols in 'cl do (print s)) (loop for s being the present-symbols in :cl do (print s)) (loop for s being the external-symbols in (find-package "COMMON LISP") do (print s)) (loop for s being each external-symbols of "COMMON LISP" ...
(loop for i from 0 to 10 do (print i)) ; prints 0 1 2 3 4 5 6 7 8 9 10 (loop for i from 0 below 10 do (print i)) ; prints 0 1 2 3 4 5 6 7 8 9 10 (loop for i from 10 above 0 do (print i)) ; prints 10 9 8 7 6 5 4 3 2 1 (loop for i from 10 to 0 do (print i)) ; prints noth...
Combining typedef with struct can make code clearer. For example: typedef struct { int x, y; } Point; as opposed to: struct Point { int x, y; }; could be declared as: Point point; instead of: struct Point point; Even better is to use the following typedef struct Poin...
The emptiness of a list is associated to the boolean False, so you don't have to check len(lst) == 0, but just lst or not lst lst = [] if not lst: print("list is empty") # Output: list is empty
Assuming that bar is an alias for someCommand -flag1. Type bar on the command line and then press Ctrl+alt+e you'll get someCommand -flag1 where bar was standing.
This example assumes you have already installed Java and Gradle. Use the following project structure: src/ main/ java/ com/ example/ Application.java build.gradle build.gradle is your build script for Gradle build system with the following content: buildscri...
You should implement SFSafariViewControllerDelegate so that your class is notified when the user hits the Done button on the SafariViewController and you can dismiss it as well. First declare your class to implement the protocol. class MyClass: SFSafariViewControllerDelegate { } Implement th...
You can add items to a user's Reading List in Safari by calling the addItem method on the SSReadingList singleton. let readingList = SSReadingList.default() readingList?.addItem(with: yourURL, title: "optional title", previewText: "optional preview text") The default Reading...
Don't forget to import the necessary framework first. import SafariServices //Objective-C @import SafariServices; Instantiate a SafariViewController instance. let safariVC = SFSafariViewController(URL: URL(string: "your_url")!) //Objective-C @import SafariServices; NSURL *URL = [...
The function map() from the package maps provides a simple starting point for creating maps with R. A basic world map can be drawn as follows: require(maps) map() The color of the outline can be changed by setting the color parameter, col, to either the character name or hex value of a color...
Considering the following dictionary: d = {"a": 1, "b": 2, "c": 3} To iterate through its keys, you can use: for key in d: print(key) Output: "a" "b" "c" This is equivalent to: for key in d.keys(): print(key) ...
Run the command below in a shell after installing Ruby. This shows how you can execute simple Ruby programs without creating a Ruby file: ruby -e 'puts "Hello World"' You can also feed a Ruby program to the interpreter's standard input. One way to do that is to use a here document in...
if /hay/ =~ 'haystack' puts "There is hay in the word haystack" end Note: The order is significant. Though 'haystack' =~ /hay/ is in most cases an equivalent, side effects might differ: Strings captured from named capture groups are assigned to local variables only when Regexp#=~...
This is the code for a simple console project, that prints "Hello, World!" to STDOUT, and exits with an exit code of 0 [<EntryPoint>] let main argv = printfn "Hello, World!" 0 Example breakdown Line-by-line: [<EntryPoint>] - A .net Attribute that m...
Say you have a library website, and you want to have a custom post type named Books. It can be registered as function create_bookposttype() { $args = array( 'public' => true, 'labels' => array( 'name' => __( 'Books' ), 'singular_name' => ...
There are 16 fundamental data types, or classes, in MATLAB. Each of these classes is in the form of a matrix or array. With the exception of function handles, this matrix or array is a minimum of 0-by-0 in size and can grow to an n-dimensional array of any size. A function handle is always scalar (1...

Page 169 of 1336