Open hiiamboris opened 1 year ago
Example from my code:
word-drawn: compose/deep/only [
translate (word-offset, 0) ;-- move to the 2D point
#debug paragraph [push [
translate (0, row-y1-1D)
fill-pen off pen magenta line-width 1
box 0x0 (word-width-1D', row-height)
]]
scale (word-scale) 1.0
clip 0x0 (word-span, total-1D/y)
translate (offset1, 0) ;-- account for word's offset within geom/size/x
(copy spaces-drawn)
]
vs
word-drawn: compose/deep/only [
translate (as-point2D word-offset 0) ;-- move to the 2D point
#debug paragraph [push [
translate (as-point2D 0 row-y1-1D)
fill-pen off pen magenta line-width 1
box 0x0 (as-point2D word-width-1D' row-height)
]]
scale (word-scale) 1.0
clip 0x0 (as-point2D word-span total-1D/y)
translate (as-point2D offset1 0) ;-- account for word's offset within geom/size/x
(copy spaces-drawn)
]
This came from
point!
design discussion: can we on top of literal(1, 2, 3)
syntax also support expressions, like(x, y, z)
, as in the original geometry point notation that we copied?Currently point can only be constructed as
make point2D! reduce [x y]
oras-point2D x y
(similarly for 3D). This sometimes becomes quite verbose, turning reader's attention on the means rather than on the goal (syntactic noise problem).We could make comma an operator that can by default:
(x1 + x2, y)
and produce apoint2D!
pair!
orpoint2D!
and a number( (x1 + x2, y), z) <=> (x1 + x2, y, z)
and produce apoint3D!
triple!
orpoint3D!
and a number and produce apoint4D!
(4D is reserved for the future for now as we don't have enough space in the cell for it in our 32-bit runtime)This will allow one to write expressions like
(x, y, z)
which will be lexed asparen!
with 5word!
s:(x , y , z)
, comma being aword!
that lexer must unstick from other tokens (x,y
not a single word but three). Parentheses are not required of course:point: x,y,z
would work the same, but in more complex expressions, likes + (x,y,z) / 2
they still make sense and add readability.Consider:
compose [offset: (0,0,0) size: (x,y,z)]
.(0,0,0)
is lexed as apoint3D!
literal value, but(x,y,z)
as a aparen!
which gets evaluated bycompose
itself.Another usage for comma would be dialects, maybe to separate items in lists e.g.
[1 2, 3 4, 5 6]
or words in sentenceslorem ipsum, dolor, sit amet
.Points against it are:
point!
syntax already collides withparen!
syntax, and(x,y,z)
expression vs(1,2,3)
literal value only adds to the confusionSo the main question here is whether the readability benefit will overweight the risks of abuse, or vice versa.