Skip to content

Commit

Permalink
Formatted examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaumgarten committed Dec 3, 2020
1 parent c3278ff commit 00b787b
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
36 changes: 18 additions & 18 deletions examples/nolol/array_user.nolol
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ define addr = :a
define write = :m

// store value at idx in array
macro set(idx,value)
write=1
data=value
addr=idx
// this will block until addr is 0.
// the array will set addr to 0 once it stored the value
wait addr
macro set(idx, value)
write = 1
data = value
addr = idx
// this will block until addr is 0.
// the array will set addr to 0 once it stored the value
wait addr
end

// retrieve value from idx
macro get(idx,value)
write=0
addr=idx
// this will block until addr is 0.
// the array will set addr to 0 once it retrieved the value
wait addr
value=data
macro get(idx, value)
write = 0
addr = idx
// this will block until addr is 0.
// the array will set addr to 0 once it retrieved the value
wait addr
value = data
end

while ++i < 5 do
insert set(i,i*2)
insert set(i, i * 2)
end

:sum = ""
while ++j < 5 do
insert get(j,retrieved)
:sum += retrieved+","
insert get(j, retrieved)
:sum += retrieved + ","
end

:done=1
:done = 1
10 changes: 5 additions & 5 deletions examples/nolol/definitions.nolol
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ define :output = :out


// your definitions can contain polaceholders (here a and b)
define addByte(a,b) = (a+b)%(2^8)
define addByte(a, b) = (a + b) % 2 ^ 8

a = 123
// definitions with placeholders can be used like functions. The aruments will replace the placeholders of the definition
:sum = addByte(a,100)
:sum = addByte(a, 100)

define foo(a,b,c,d) = a+b+c+d
define foo(a, b, c, d) = a + b + c + d

// Any valid expression can be used as value for a placeholder
:bar = foo(greeting,","," "+:name,addByte(a,60))
:bar = foo(greeting, ",", " " + :name, addByte(a, 60))

define pop(string) = string- --string
define pop(string) = string - --string

:done = 1
2 changes: 1 addition & 1 deletion examples/nolol/fizzbuzz.nolol
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ while :number <= upto do
end
end
:number++
end
end
4 changes: 2 additions & 2 deletions examples/nolol/ifelse.nolol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end
// The old yolol-inline ifs can still be useful. For example if you absolutely need to make sure everything happens in one line.
// In this example, the two assignments and the if are guaranteed to happen on the same tick.
// To avoid confusion, when you need an inline-if, you need to use the "_if" keyword
a=1 ; _if 1==1 then :foo=1 else :foo=2 end ; b=2
a = 1; _if 1 == 1 then :foo = 1 else :foo = 2 end; b = 2

:other = "done"
:done = 1
:done = 1
8 changes: 4 additions & 4 deletions examples/nolol/macros.nolol
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ define separator = "_"

insert greet(:out2, "you")

avar="foo"
avar = "foo"

// because all non-global vars are private to an insertion of a macro, this does not work
// the code inside the macro does not have access to the variable avar defined above
macro doesntwork()
:out3=avar
:out3 = avar
end
insert doesntwork()

// to give the code inside the macro access to an outside var, you either need to pass the var as an argument, or
// mark the variable as an external variable. You can do this as follows:
macro works()(avar)
:out4=avar
:out4 = avar
end
insert works()

:done = 1
:done = 1
2 changes: 1 addition & 1 deletion examples/nolol/measuring_time.nolol
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ wait time() < closewhen then :door = "closed" ; closedAfter = time() - start end

//note: wait is effectively just syntactic sugar
// the wait line above can also be written as
_if time() < closewhen then _goto line() end ; :door = "closed" ; closedAfter = time() - start $
_if time() < closewhen then _goto line() end; :door = "closed"; closedAfter = time() - start $
2 changes: 1 addition & 1 deletion examples/nolol/state_one.nolol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ end
insert SMBEGIN(STATE_PING)

:OUTPUT += "ping "
:counter++
:counter++

insert SMEND(STATE_PONG)
6 changes: 3 additions & 3 deletions examples/yolol/abuse_errors.yolol
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
:a = 123 x=1/0 :a = 456 // last assignment is not executed
:b = 1 // execution continues on last line
:done = 1
:a=123 x=1/0 :a=456 // last assignment is not executed
:b=1 // execution continues on last line
:done=1
2 changes: 1 addition & 1 deletion examples/yolol/case_insensitive.yolol
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ FoO="test"
:derefok=Foo==FoO
:funcOK=sin 3==sin 3
if foo==FOO then :ifok=1 end
:done = 1
:done=1
2 changes: 1 addition & 1 deletion examples/yolol/operations2.yolol
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ abc="abc"
:testif=0
pi=3.141
if pi>3 then :testif=1 else :testif=0 end
:done = 1
:done=1

0 comments on commit 00b787b

Please sign in to comment.