Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ Esc Interpreter, Esc Macros and templates » bug in Esc manual page?
BugQuestion.gif  bug in Esc manual page? [message #2107] Sat, 01 April 2006 14:06 Go to next message
hojtsy is currently offline  hojtsy
Messages: 239
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
In Esc manual page there is this line:
s[1, -1] = "xXx";    // s is now "1xXx4"

Is -1 the slice element count here? I supposed that it could only be positive number.
I also think that this other example has some error. How do the interpreter know in the last line that x means var1.x ?
var.x = 0;
var.Next = @() { .x++; };
var.Next();            // var.x is now 1
var1.x = 0;
var.Next()! x;            // var1.x is now 1


BTW, I tried searching for esc files in the U++ installation, to see some examples, but there seems to be none. Maybe some example files could be put in, to make the syntax and usage more straightforward. How do you use Esc in a C++ application, how are the functions are invoked, and how are the return values retrieved? Is there a connection between Esc and Usc? Usc files seems to have a different syntax than the one desribed for Esc. Is there a manual for Usc?

[Updated on: Thu, 04 May 2006 17:16] by Moderator

Report message to a moderator

Re: bug in Esc manual page? [message #2112 is a reply to message #2107] Sat, 01 April 2006 16:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11179
Registered: November 2005
Ultimate Member
hojtsy wrote on Sat, 01 April 2006 07:06

In Esc manual page there is this line:
s[1, -1] = "xXx";    // s is now "1xXx4"

Is -1 the slice element count here? I supposed that it could only be positive number.
I also think that this other example has some error. How do the interpreter know in the last line that x means var1.x ?
var.x = 0;
var.Next = @() { .x++; };
var.Next();            // var.x is now 1
var1.x = 0;
var.Next()! x;            // var1.x is now 1


BTW, I tried searching for esc files in the U++ installation, to see some examples, but there seems to be none. Maybe some example files could be put in, to make the syntax and usage more straightforward. How do you use Esc in a C++ application, how are the functions are invoked, and how are the return values retrieved? Is there a connection between Esc and Usc? Usc files seems to have a different syntax than the one desribed for Esc. Is there a manual for Usc?


Documentation bugs - fixed (negative index is possible, but it should be ":" slice, and "var.Nect() ! var1" instead.

I will try to create some reference\Esc soon.

Usc / Esc relation - Usc is Esc "application" - it is using Esc interpreter as "engine", but (exactly in a Esc design direction - it is "Embeddable Script" Smile adds more syntax to it. But the actual code (in both widget descriptions and TheIDE macros) is Esc.

Mirek
Re: bug in Esc manual page? [message #2247 is a reply to message #2112] Wed, 05 April 2006 10:45 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11179
Registered: November 2005
Ultimate Member
OK, reference/EscDev is the "introductory" Esc example. It does not cover "objects" and uses just trivial script interpretation (without extensions, as with usc)

I will yet have to find some nice simple examples to demonstrate those....

#include <Esc/Esc.h>

void SIC_Print(EscEscape& e)
{
	if(e[0].IsArray())
		Cout() << (String) e[0];
	else
	if(e[0].IsNumber())
		Cout() << e[0].GetNumber();
	else
	if(!e[0].IsVoid())
		e.ThrowError("invalid argument to 'Print'");
}

void SIC_Input(EscEscape& e)
{
	e = ReadStdIn();
}

void SIC_InputNumber(EscEscape& e)
{
	e = atof(ReadStdIn());
}

CONSOLE_APP_MAIN
{
	ArrayMap<String, EscValue> global;
	Escape(global, "Print(x)", SIC_Print);
	Escape(global, "Input()", SIC_Input);
	Escape(global, "InputNumber()", SIC_InputNumber);
	StdLib(global);
	try {
		Scan(global, LoadFile(GetDataFile("script.esc")));
		Execute(global, "main", INT_MAX);
	}
	catch(CParser::Error e) {
		Cout() << "ERROR: " << e << "\n";
	}
}


demonstration Esc script (script.esc):

getnumber()
{
	for(;;) {
		h = InputNumber();
		if(h > 0)
			return h;
		Print("Please enter a positive number!\n");
	}
}

main() {
	Print("What is your name?\n");
	name = Input();
	Print("Hi " + name + "!\n");
	Print("How tall are you? (in cm please!)\n");
	h = getnumber();
	Print("What is your weight? (in kg please!)\n");
	w = getnumber();
	bmi = w / (h * h / 10000);
	Print("Your body mass index is " + to_string(bmi) + "\n");
	Print(name + ", ");
	if(bmi >= 35)
		Print("you are morbidly fat!!!");
	else
	if(bmi >= 30)
		Print("you are fat!!!");
	else
	if(bmi >= 25)
		Print("you are overweight!");
	else
	if(bmi >= 18.5)
		Print("your weight is OK.");
	else
		Print("your are too slim!");
	Print("\nThanks for a nice chat!\n");
}


Mirek
Re: bug in Esc manual page? [message #5031 is a reply to message #2247] Thu, 31 August 2006 16:12 Go to previous messageGo to next message
groszd is currently offline  groszd
Messages: 1
Registered: August 2006
Location: Budapest
Junior Member
According to the documentation, function definition is #lambda(){} . Can the # be omitted (like in this code: main() ... )?
Re: bug in Esc manual page? [message #5032 is a reply to message #5031] Thu, 31 August 2006 17:27 Go to previous message
mirek is currently offline  mirek
Messages: 11179
Registered: November 2005
Ultimate Member
No.

However, #lambda() is the shortcut definition INSIDE function body.

Embedding application can implement adding "C-like" function definitions as global lambda variables; Scan function does that too (but you do not need to use Scan to embed Esc).

So the "practical" answer is in fact yes Smile

Mirek
Previous Topic: *.upt Empty lines produced in "Preview" - a bug?
Next Topic: REPL
Goto Forum:
  


Current Time: Mon Dec 11 15:53:20 CET 2017

Total time taken to generate the page: 0.01071 seconds