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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 logic.rb(main):001:0> #! /usr/bin/env ruby
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 logic.rb(main):002:0*
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 logic.rb(main):003:0* x = 4
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 => 4
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 logic.rb(main):004:0>
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 logic.rb(main):005:0* # "if" block is "if… end" - no "then" required
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 logic.rb(main):006:0* if x == 4
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 logic.rb(main):007:1> puts "x equals 4"
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 logic.rb(main):008:1> end
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 x equals 4
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 => nil
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 logic.rb(main):009:0>
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 logic.rb(main):010:0* # Python- and Perl-like following logic also works
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 logic.rb(main):011:0* puts "x equals 4" if x == 4
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 x equals 4
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 => nil
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 logic.rb(main):012:0> puts "x equals 4" unless x != 4
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 x equals 4
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 => nil
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 logic.rb(main):013:0>
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 logic.rb(main):014:0* # Negation has many forms.
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 logic.rb(main):015:0* # Simple logic:
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 logic.rb(main):016:0* if x != 5
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 logic.rb(main):017:1> puts "x not equal 5"
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 logic.rb(main):018:1> end
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 x not equal 5
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 => nil
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 logic.rb(main):019:0>
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 logic.rb(main):020:0* # Two options on negation
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 logic.rb(main):021:0* if !(x == 5)
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 logic.rb(main):022:1> puts "x not equal 5"
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 logic.rb(main):023:1> end
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 x not equal 5
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 => nil
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 logic.rb(main):024:0>
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 logic.rb(main):025:0* if not x == 5
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 logic.rb(main):026:1> puts "x not equal 5"
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 logic.rb(main):027:1> end
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 x not equal 5
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 => nil
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 logic.rb(main):028:0>
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 logic.rb(main):029:0* # "unless" blocks instead of "if"
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 logic.rb(main):030:0* unless x != 4
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 logic.rb(main):031:1> puts "x equal 4"
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 logic.rb(main):032:1> else
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 x equal 4
700c167cad9f Add some basic logic examples
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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