do

evaluate and execute given code


Parameters

do code :string :block :bytecode

Attributes

times:integerrepeat block execution given number of times

Returns

  • :any

Examples

copy
do "print 123" ; 123

copy
do [ x: 3 print ["x =>" x] ; x => 3 ]

copy
print do "https://raw.githubusercontent.com/arturo-lang/arturo/master/examples/projecteuler/euler1.art" ; 233168

copy
do.times: 3 [ print "Hello!" ] ; Hello! ; Hello! ; Hello!

copy
; Importing modules ; let's say you have a 'module.art' with this code: ; ; pi: 3.14 ; ; hello: $[name :string] [ ; print ["Hello" name] ;] do relative "module.art" print pi ; 3.14 do [ hello "John Doe" ; Hello John Doe ] ; Note: always use imported functions inside a 'do block ; since they need to be evaluated beforehand. ; On the other hand, simple variables can be used without ; issues, as 'pi in this example

Related