You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 }
The text was updated successfully, but these errors were encountered:
I think you have a wrong conceptual model of what ribosome is. To make it simple, imagine that every line starting with dot is actually a print statement. Thus:
Hi! I'm trying to make a simple macro called
unless
, which generatesif not expr:
line, but it's not quite clear how to do it with ribosome.My attempt is:
but it generates:
So, lines go directly to output, and programmer has no access to them. I checked ribosome code and found that these
None
s were returned fromdot
method. Changing it togave me something better:
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 ofI would prefer something like
And with blocks:
The text was updated successfully, but these errors were encountered: