There's a REPL in Codea?

I read in iTunes that Codea now has a REPL (read-eval-print-loop). My simple question is: where is it?

@starblue, the REPL Codea uses seems to be on a line by line basis. As in, you start typing, it evaluates that and gives you a list of functions available. You use one of those functions and start typing in the parameters, and once again, it reads the parameters you are entering and let’s you know that x and y go here and there, width and height go in these places.

Edit: There are some programs out there that utilize more advanced REPL systems in which it will output the results of code blocks. Would be cool if Codea could do this, but it is not required at all IMO.

It’s had one for awhile :slight_smile:

When you run your program, there’s a text entry field underneath the debug output window…that’s the text entry field for the REPL. You have to be using the standard display mode, because the side panel with the debug console is hidden in full screen mode.

EDIT: @Slashin8r: what you are describing is not the REPL, that is part of Codea’s help system, or “intellisense”. Codea has a proper REPL in the debug console of a running program.

@slashin8r, @toadkick, I understood the REPL in Codea to be Air Code.
To access it press on the button in the top left section of the Codea main menu

@toadkick, intellisense is a utilization of REPL. And now that you mention the output window, that too is another utilization of REPL. Same with when Codea doesn’t even let you run the project and highlights text and tabs in red to show where the errors are.

@Jordan: Nope, AirCode is a separate feature. As @starblue notes, REPL stands for read-eval-print loop. That’s what the code for the text entry field does in the debug console: it reads what you type in, evaluates it, and prints the result, and it runs in an infinite loop. It’s very useful for testing out tiny snippets of code.

@Slashin8r: All I’m saying is, conceptually “intellisense” is different than what most people describe/think of traditionally as a REPL, which I believe is what the OP was asking about. Just trying to reduce confusion :slight_smile:

For intellisense, Codea has to constantly evaluate what you are typing in and change its display results based on what you type in. That’s the exact definition of REPL. It’s a way more advanced REPL than the text input into the output window (which is the most basic REPL implementation).

Sorry if I confused anyone, just wanted to clarify that REPL is used in many more instances. I’m sure many of us utilize that structure within our own programs without even knowing it :wink:

Dude, I’m not trying to start an argument. OP was asking about a REPL. What you described was not what @starblue was asking for, and really doesn’t help solve his problem. Whether intellisense is implemented using a REPL is irrelevant.

I’m not trying to start an argument. I’m simply replying to the OP’s question. Seems to me like you do want an argument since you are making assumptions on the true nature of the OP’s question… I’m just trying to provide as much info to the question as I can.

OK, the text entry field at the bottom of the output window is the REPL.

So how do you use it? Transcript:

> i = 1             --enter a variable
>> nil              --OK
> i                 --show it
>> 1                --OK
> i + 1             --show value of expression
>> attempt to call a string value   -- fails
> Plot              --one of my classes
>> table: 0x26b03a70   --OK
> Plot.normalize    --method in class (I believe this is how you reference it)
>> attempt to call a string value  --fails (thought it'd be "function")
> Plot:normalize    --method again 
>> attempt to call a string value   --fails (this one was expected)
> commands          --a file-level variable (i.e. "local commands" at file toplevel)
>> attempt to call a string value  --result is supposed to be a table
> j = 2             --enter 2nd variable
>> nil              --OK
> i + j             --show value of expression
>> attempt to call a string value   --fails
> 3 * 5             --multiply 2 constants
>> attempt to call a string value  --can't even do that

Looks to me like the REPL’s pretty useless. Can’t even multiply 2 literal numbers together and see the answer (so forget using it for a cheap calculator). The only thing that might require a “trick” is getting to a file-local variable–I’m sure I didn’t refer to it correctly. But if you tell me such variables are “invisible”, then the REPL’s useless. I don’t use globals anywhere except where Codea forces them.

@Slashin8r. What you described in your first message is not a REPL–there’s no evaluation of expressions nor the automatic printing of the results. What you described is autocompletion plus context (I guess that’s what “intellisense” is). That’s a great feature too, but it’s not a REPL. A REPL is an interactive interpreter for a computer language. Lisp defined the original version (circa early 60’s) and many dynamic languages since then have had them.

@starblue, not to argue, but to confirm. If you look up the definition of intellisense, it will tell you it is the combination of “REPL” and “REPLACE”. REPL is not a program but a code structure and can be utilized in many different formats. For example, one format is the original Lisp version. Other programs utilize this coding structure in many different fashions, besides the basic command line version.

Edit: Now I won’t bother posting anymore in here since the OP has clarified the nature of the question and I would be going off topic.

@starblue for a cheap calculator try print(3*5) :wink:

@starblue: When you enter code into the REPL, it is compiled using Lua’s loadstring(), which returns a function. Codea runs this function, and prints the returned result(s). Try this:

return 3 * 5

Also, yeah, you can only reference globals from the REPL, but I still find it to be quite useful for a lot of things.

@XanDDemoX: I know “print” works, but it’s supposed to be a REPL–read-eval-print-loop–if there’s no printing, it’s not a REPL.

@toadkick: If Lua is creating a function around my input, it can also create a “return” in front of it. (Why does "i’ work but “i+1” fail?) My program has only 1 “global”, which is really a “local var” declaration in one tab. I have lots of tabs, but all interactions with the var must go through the first tab. In Lua terms, I have defined no globals myself (I know Codea does). So if there’s no way to specify file-local variables, that makes the REPL pretty useless.

The reason the print in read-eval-print-loop does not work is because there is nothing to evaluate. i + 1 does not work because it is invalid Lua. loadstring() returns a function that Codea then runs. If the function made by loadstring() returns something, it prints it. return i + 1 would be fine. Codea would then print it. print(i + 1) would work, too. It does not return a value for Codea to print, though since it calls print() in the function anyway, it does not matter. In short, the print in read-eval-print-loop only does something if the function created by loadstring() returns a value. (Setting a variable returns nil.)

Edit: There’s an REPL in Codea? Sorry. Grammar freak here.

I don’t understand. I set “i” to 1. I entered “i” into the REPL, it printed “1”, so it knows “i” exists and is equal to 1. Then I enter “i+1” into the REPL, I expect “2”, instead I get back an error. Why is “i” legal Lua and “i+1” not legal Lua? “return i” is legal, and so is “return i + 1”. I don’t get the distinction.

Do you know of any way to refer to a file-local variable in the REPL? Maybe through some metatable?