Mercurial > repos > other > SevenLanguagesInSevenWeeks
annotate 1-Ruby/logic-irb.output @ 44:6347bacb3be7
Add more notes about the DSL while I think about it
Note: Several things don't make sense
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 18 Sep 2017 20:53:36 +0100 |
parents | e5b84cc7bc29 |
children |
rev | line source |
---|---|
8 | 1 logic.rb(main):001:0> #! /usr/bin/env ruby |
2 logic.rb(main):002:0* | |
3 logic.rb(main):003:0* x = 4 | |
4 => 4 | |
5 logic.rb(main):004:0> | |
6 logic.rb(main):005:0* # "if" block is "if… end" - no "then" required | |
7 logic.rb(main):006:0* if x == 4 | |
8 logic.rb(main):007:1> puts "x equals 4" | |
9 logic.rb(main):008:1> end | |
10 x equals 4 | |
11 => nil | |
12 logic.rb(main):009:0> | |
13 logic.rb(main):010:0* # Python- and Perl-like following logic also works | |
14 logic.rb(main):011:0* puts "x equals 4" if x == 4 | |
15 x equals 4 | |
16 => nil | |
17 logic.rb(main):012:0> puts "x equals 4" unless x != 4 | |
18 x equals 4 | |
19 => nil | |
20 logic.rb(main):013:0> | |
21 logic.rb(main):014:0* # Negation has many forms. | |
22 logic.rb(main):015:0* # Simple logic: | |
23 logic.rb(main):016:0* if x != 5 | |
24 logic.rb(main):017:1> puts "x not equal 5" | |
25 logic.rb(main):018:1> end | |
26 x not equal 5 | |
27 => nil | |
28 logic.rb(main):019:0> | |
29 logic.rb(main):020:0* # Two options on negation | |
30 logic.rb(main):021:0* if !(x == 5) | |
31 logic.rb(main):022:1> puts "x not equal 5" | |
32 logic.rb(main):023:1> end | |
33 x not equal 5 | |
34 => nil | |
35 logic.rb(main):024:0> | |
36 logic.rb(main):025:0* if not x == 5 | |
37 logic.rb(main):026:1> puts "x not equal 5" | |
38 logic.rb(main):027:1> end | |
39 x not equal 5 | |
40 => nil | |
41 logic.rb(main):028:0> | |
42 logic.rb(main):029:0* # "unless" blocks instead of "if" | |
43 logic.rb(main):030:0* unless x != 4 | |
44 logic.rb(main):031:1> puts "x equal 4" | |
45 logic.rb(main):032:1> else | |
46 logic.rb(main):033:1* puts "x not equals 4" | |
12
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
47 logic.rb(main):034:1> end |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
48 x equal 4 |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
49 => nil |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
50 logic.rb(main):035:0> |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
51 logic.rb(main):036:0* # "then" is optional, except in single line statement |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
52 logic.rb(main):037:0* if x == 4 then puts "x equal 4" end |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
53 x equal 4 |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
54 => nil |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
55 logic.rb(main):038:0> if x == 4 then |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
56 logic.rb(main):039:1* puts "x equal 4" |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
57 logic.rb(main):040:1> end |
8 | 58 x equal 4 |
59 => nil | |
12
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
60 logic.rb(main):041:0> if x == 4 |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
61 logic.rb(main):042:1> puts "x equal 4" |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
62 logic.rb(main):043:1> end |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
63 x equal 4 |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
64 => nil |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
65 logic.rb(main):044:0> # The following line gives: |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
66 logic.rb(main):045:0* # logic.rb:…: syntax error, unexpected tIDENTIFIER, expecting keyword_then or ';' or '\n' |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
67 logic.rb(main):046:0* # if x == 4 puts "x equal 4" end |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
68 logic.rb(main):047:0* # |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
69 logic.rb(main):048:0* # if x == 4 puts "x equal 4" endlogic.rb(main):048:0# |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
70 logic.rb(main):048:0# |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
71 logic.rb(main):048:0# |
e5b84cc7bc29
Update logic script re: "then" in "if else" statements
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
72 => nil |