Prexonite, a .NET hosted scripting language with a focus on meta-programming and embedded DSLs
0

Configure Feed

Select the types of activity you want to include in your feed.

PRX-37 REPL move println out of generated function

We still print the expression, but the `println` call is no longer part of the generated function. This makes the output of `:compile` less confusing.

Christian Klauser (Apr 28, 2021, 1:27 PM +0200) d88018f5 b432ad50

+12 -4
+12 -4
Prx/src/prx_interactive.pxs
··· 214 214 var lowRaw = raw.ToLower; 215 215 var funcId = nextFuncId; //<-- get the first unique function id 216 216 var cmd = "r"; //<-- assume execution of code 217 + var printPrefix = null; //<-- text to print before running the user input (if non-null) 217 218 218 219 if(lowRaw == ":r" or lowRaw == ":reload") //this directive restarts prx\main with the same arguments. See 'prx_main.pxs' for details. 219 220 { ··· 282 283 else 283 284 { 284 285 executeStatement: 286 + var printPrefix = shortened(raw) + " = "; 285 287 //First, try to compile the code as an expression 286 - buffer.AppendFormat(" function {0}() does println = \"{1} = \" + ( \n{2}\n ) ; ", 287 - [funcId, shortened(raw).Escape, raw]~Object<"System.Object[]">); 288 + buffer.AppendFormat(" function {0}() = (\n{1}\n); ", 289 + [funcId, raw]~Object<"System.Object[]">); 288 290 if(Not tryLoad) 289 291 { 290 292 //should that fail, try to compile the code as a statement ··· 294 296 funcId = nextFuncId; 295 297 buffer.AppendFormat(" function {0}() {{ \n{1}\n ; }} ", 296 298 [funcId, raw]~Object<"System.Object[]">); 299 + printPrefix = null; 297 300 298 301 if(Not tryLoad) 299 302 { ··· 319 322 if(cmd == "r") 320 323 { 321 324 //A function needs to be run 322 - unless(app.Functions[funcId] is Null) 323 - app.Functions[funcId].Run(engine); 325 + if(printPrefix != null) { 326 + print(printPrefix); 327 + } 328 + if(!app.Functions[funcId] is Null) { 329 + var result = app.Functions[funcId].Run(engine); 330 + println(result.self); 331 + } 324 332 } 325 333 else if(cmd == "c") 326 334 {