Jump to content

Ternary operator and recursion and execute/eval/assign


junkew
 Share

Recommended Posts

Out of curiosity no real issue to fix. Can I do recursion with the ?: operators? in combination with eval, assign, execute functions

Example 3 breaks whereas 1 and 2 are fine

Global $j=3
;~ Example 1
Global $trick="$j<10 ?  4 : 5"
Global $j=execute($trick)
consolewrite($j & @crlf)

;~ Example 2
Global $a="$j+2"
Global $trick="eval(""j"")<10 ?  execute(eval(""a"")) :  (execute(eval(""a"")) * 5)"
$j=execute($trick)
consolewrite($j & @crlf)
consolewrite($trick & @crlf)

;~ Example 3
Global $a="$j+2"
Global $trick="eval(""j"")<10 ?  (execute(eval(""a"")) + (execute(eval(""trick""))*0) ) :  (execute(eval(""a"")) * 5)"
$j=execute($trick)
consolewrite($j & @crlf)

;~ consolewrite($x & @crlf)
consolewrite($trick & @crlf)
Exit
  • Wondering if you can do something like this (pseudocode)
$trick="($j=<10) ? $j=j+1 + (consolewrite($j) & @CRLF ) + execute($trick) : (consolewrite("end" & @CRLF))
  • I can imagine then I have to use more functions like assign, execute, eval etc.
$trick="($j=<10) ? assign(""j"",execute(""j+1"")) + (consolewrite($j) & @CRLF ) + execute($trick) : (consolewrite("end" & @CRLF))

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...