Author Topic: 'Inline If' Statement  (Read 6376 times)

0 Members and 1 Guest are viewing this topic.

Offline gumby

Re: 'Inline If' Statement
« Reply #15 on: January 20, 2011, 08:10:36 AM »
I think I made a mistake in my testing.  I came to same conclusion (this morning) that the order of parameters is unimportant.  The expression would be evaluated before passing it to the procedure.  I'll test this tonight, but I'm nearly sure the order should make no difference.  I don't see why I had such a problem with understanding this.  You can do similar things in other languages (providing an expression for a parameter).  Maybe it's because I'm still struggling with infix vs. prefix syntax & the lack of commas between procedure arguments?

You are both right, that eval() procedure is downright silly...  where did I put my dunce cap?

Thanks again for the help, guys...

« Last Edit: January 20, 2011, 11:21:46 AM by gumby »
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline lance.ewing

Re: 'Inline If' Statement
« Reply #16 on: January 20, 2011, 04:35:01 PM »
That being said, it certainly seems like it would be possible to modify the compiler to allow for something like this (i.e. passing lambda functions to procedures).

This reminds me of what has been happening with the Java VM. Languages such as Clojure and Scala compile to the JVM, as do many others. Having closures and passing functions as objects is where things get really powerful. I wonder how far a compiler could go with the SCI VM?

Offline gumby

Re: 'Inline If' Statement
« Reply #17 on: January 20, 2011, 09:09:29 PM »
I've confirmed that parameter order does not matter (which makes perfect sense).

For those interested, here is the final code that I can up with - just with the parameters in a different order :)
Code: [Select]
(procedure public (iif pCondition pTrue pFalse)
   (if (pCondition)
     return pTrue
   )(else
     return pFalse
   )
)
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Collector

Re: 'Inline If' Statement
« Reply #18 on: January 21, 2011, 04:35:02 AM »
are you going to put something about it in the Wiki?
KQII Remake Pic

Offline gumby

In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Collector

Re: 'Inline If' Statement
« Reply #20 on: January 21, 2011, 12:25:18 PM »
Our Wiki is starting to flesh out nicely.
KQII Remake Pic

Offline gumby

Re: 'Inline If' Statement
« Reply #21 on: February 13, 2012, 10:40:39 PM »
The real question though is whether the compiler will let you put an "if" into this context, e.g. the compiler would have to allow this kind of code:

(= someVar (if (<condition>) (<first-value>) else (<second-value>)))

I recently revisited this inline-if issue.  The syntax suggested above is perfectly valid, it's just that Companion won't allow it.  This does work in Studio.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition


SMF 2.0.14 | SMF © 2017, Simple Machines
Simple Audio Video Embedder

Page created in 0.099 seconds with 23 queries.