]> ocean-lang.org Git - ocean-D/blob - Ocean-operators
updates
[ocean-D] / Ocean-operators
1
2 Operators.
3 I currently have
4
5 Binary: and or < > <= >= == !=  + - * / % ++
6 prefix: not + -
7
8 I might want:
9
10  Binary: and then, or else, integer division
11  Prefix: int
12  Suffix: dereference
13
14
15  Do I want  COND ? IFTRUE : IFFALSE
16    or       IFTRUE if COND else IFFALSE
17
18   Can    / NUMBER
19    provide the integer part?
20
21  What can I use '!' '@' '#' '$' '^' '&' '*' '|'
22    for
23
24  bit-wise and/or/not/xor
25
26     != is 'xor' for Boolean
27
28  I should use & | ~ for bitwise. and or not
29     ~ could be an infix for xor
30     &~  could clear bits
31
32  What foo= options?
33    += -= *= /= %= &= |= ~=
34
35  Do I want "#n" to be (1 << n) ??
36
37  ++ is concat.  What about
38     --
39     **
40     // - comment
41     @@
42     ^^
43     &&
44     ||  These last two are best avoided.
45
46  Pointers ... do I need a dereference operator?
47   Normally a pointer refers to the object it references (which isn't a pointer)
48    The only difficulty is
49           a = b
50    If a:foo and b:foo^  then b is dereferenced.
51    If a:foo^ and b:foo  then a points to b
52    if a:foo^ and b:foo^ then a points to what b points to
53
54    So how do you change what a points to?  I could have a de-reference operation
55       *a = b;  a^ = b
56    but I think I want a structure-changing assignment
57       a @= b
58    then maybe
59       a @@= b
60    does a deep copy
61
62 What types do operators act one?
63
64    numbers  + - * / %
65    bitsets  & | ~ &~
66    Boolean  and or not "and then" "or else" "if .. else"     What about and= ??  *= ??
67    string   ++  < > == etc,  regexp? strlen? append?
68    character?  add to string?  Convert to string?
69
70    are << and >> operators on numbers or bitsets?
71    can I just use "*# or /#" ??
72
73
74    What about error encoding?  e.g. a pointer can have nil or other error encoded
75    A range-limited number could have extra codes outside that range.
76    Need to be able to :
77       convert error to type     !error
78       test if value is error    ?value
79       extract error code        value!
80
81
82 PROBLEM??
83
84   a if c else b
85 could have a natural precedence:
86
87   A if C else B if q else a if c else b
88 would be
89   A if C else (B if q else (a if c else b))
90 Hmm..  not what I imagined.  But what I imaging suggested that left-association what
91  a op b op c -> (a op b) op c
92 requires that we reduce even when we could shift, ... maybe .... I should leave this
93 until I do precedence.
94
95 --------------------------
96
97 Thinking about bit operators.
98
99 #foo  is 2^foo
100 So #12-#4 is
101     1000000000000 -
102             10000
103 =    111111110000
104 which is bits 4 thru 11
105
106 I'm wondering if it is useful to have a field-select operator,
107 which could be '#' as infix (rather than prefix) so
108
109   var # field
110
111 would be an lval which can only modify the selected bits
112
113   var # #12-#4 = #6-#4
114 would clear bits 6-11.  Doesn't actually read very well, does it?
115 Probably better to use field syntax, with a way to declare fields for an int.
116 This would be a record.
117
118 Still.
119    var &~= #4
120    var |= #4
121 to clear and set bits looks OK.
122 But ... what syntax do I want for test-and-set?  More genericly cmpxchg.
123 An operator that modifies a variable is something I wanted to avoid.
124   var ? oldval = newval
125 could 'use false' if it fails.