(define file (open-input-file "turing.txt"))
(define readFile
(lambda (p)
(let f ((x (read p)))
(if (eof-object? x)
'()
(cons x (f (read p)))))))
(readFile file)
(1966
Alan
Perlis
Yale
University
Compilers
1967
Maurice
Wilkes
University
of
Cambridge
Hardware
1968
Richard
Hamming
Bell
Telephone
Laboratories
Coding
Systems
1969
Marvin
Minsky
MIT
AI
.
.
.
2012
Silvio
Micali
MIT
Complexity
Theory
2013
Leslie
Lamport
Microsoft
Research
Distributed
Systems
2014
Michael
Stonebraker
MIT
Databases)
(define file (open-output-file "schemeOut.txt"))
(write `("A" "small" "little" "text" "file") file)
("A" "small" "little" "text" "file")
(define file (open-output-file "schemeOut2.txt"))
(map (lambda (x) (write x file)) `("A" "small" "little" "text" "file"))
(#<void> #<void> #<void> #<void> #<void>)
"A""small""little""text""file"
(define file (open-output-file "schemeOut3.txt"))
(map (lambda (x) (display x file)) `("A" "small" "little" "text" "file"))
(#<void> #<void> #<void> #<void> #<void>)
Asmalllittletextfile
(sort listToBeSorted sortFunction)
To sort a list of numbers
(sort `(2 48 1 0 -1 100) <)
Which results in
(-1 0 1 2 48 100)
A more complex function can be used
(sort `((1 3 4) (2 49 0) (0 1 2)) (lambda (x y) (< (cadr x) (cadr y))))
Which gives
((0 1 2) (1 3 4) (2 49 0))
lambda var1,var2,....: expression
square = lambda x: x*x
square(10)
add = lambda a,b: a + b
add(1,2)
map(function, iter1, iter2,.....,iterN)
map(int,["1",'2',"3","4"])
map(str.capitalize,["this","IS",'really',"USeful"])
map(lambda x: x.capitalize(), ["this","WORKS",'TOo'])
map(lambda x: x + " ", "What about this")
map(lambda x,y: x + " " + y , "What is this", "Another Stri")
map(lambda x: x,{"dog":1,"cat":2,"frog":3})
filter(function, iterable)
filter(lambda x: x > 0, [-5,2,-59,3])
filter(lambda x: x > 'm',"String")
filter(lambda x: type(x) == str, ["String",1000, ["string"], {"key":1}, 100.2,"String2"])
(var1, var2, ....) -> { stmt1; stmt2; .... }
var -> stmt
ArrayList<String> strings =
new ArrayList<String>(
Arrays.asList("Artificial Intelligence", "Theory", "Cybersecurity", "Machine Learning", "Computational Vision", "Data Visualization", "Computer Graphics", "Information Retrieval", "Wearable Computing", "Databases"));
strings.forEach(p -> System.out.println(p));
List<Double> squares = numbers.stream().map(num -> num * num).collect(Collectors.toList());
Map<String,Integer> lambdaTotals = words.stream().filter(p -> p.getKey().endsWith("_ADJ")).collect(
Collectors.groupingBy(x -> x.getKey().toLowerCase(),Collectors.summingInt(y -> y.getValue())));