-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Hi! I'm trying to make a simple macro called unless, which generates if not expr: line, but it's not quite clear how to do it with ribosome.
My attempt is:
#!/usr/bin/env python
def unless(x, text):
.if not @{x}:
. @{text}
def main():
for i in range(3):
.var@{i} = @{i*10}
unless(
.var0
,
.print var2
)
main()
but it generates:
var0 = 0
var1 = 10
var2 = 20
var0
var2
if not None:
None
So, lines go directly to output, and programmer has no access to them. I checked ribosome code and found that these Nones were returned from dot method. Changing it to
# Adds newline followed by one . line from the DNA file.
@staticmethod
def dot(line, bind):
Block.stack[-1].append(Block(''))
Block.add(line, bind)
return line
gave me something better:
var0 = 0
var1 = 10
var2 = 20
var0
print var2
if not var0:
print var2
But these lines still go directly to output. So, am I missing something? Is it possible to make unless with ribosome? Is it that complex to work with tokens, instead of whole lines? Instead of
unless(
.var0
,
.print var2
)
I would prefer something like
.`{unless( .var0 , .print var2 )}
And with blocks:
.`{unless( .var0 ,
.` print 1
.` print 2 }
Metadata
Metadata
Assignees
Labels
No labels