Page 1 of 1

More flexible syntax

Posted: Mon Jun 04, 2012 10:09 am
by Hydrate
After toying with many other languages for a while I have come to the conclusion that Purebasic is missing a massive feature that many have in its syntax. Of course that is the ability to have anonymous inner procedures. Not just that though, but some syntax changes which I think would take Purebaic to an entirely new level (and shouldn't be too hard to implement).

Consider the following code:

Code: Select all

var1 = Procedure getStuff();
  
EndProcedure;
This is not possible in Purebasic, of course it sees 'Procedure' as a keyword and tells me no. What it should do is create the procedure and return the address of the procedure to var1 (so var1 = @getStuff()). Why is this essential? Too often do I find I need to declare a procedure, and then assign its address to a variable, which is fine in smaller code, but as projects get larger it becomes more difficult to manage. Without it Purebasic lacks an element of scalability.

Scoping is also something I would like to look at. Consider I have a procedure where I have a variable ('a') which is protected. Much like in the Purebasic examples.

Code: Select all

Global a
  a = 10
  
  Procedure Change()
    Protected a
    a = 20 
  EndProcedure 
  
  Change()
  Debug a ; Will print 10, as the variable has been protected.
This code allows 'a' to be changed by calling only that procedure. Suppose I now have 'a' 'b' and 'c' as my variables all protected in that procedure. I need to edit each one depending entirely on what the values of them are or something like that. I can do it all in a single procedure... but it would be much nicer to have it all separated out so it is easier to read and maintain later into separate functions for each one. Of course I cannot do that, because it is protected.

Now consider this:

Code: Select all

  Procedure Change()
    Protected a
    Protected b
    Protected c
    editA();
    editB();
    editC();

    Procedure editA();
       if a = blah
          a = blah
        endif
    EndProcedure
  EndProcedure 
  
  Change()
The inner procedure (which can only be called from that procedure) has done most of the work for me.

I would very much like to be able to do things like create structures inside a procedure as well (with protected access to that procedure).

I think adding functionality like this would make Purebasic a significantly more flexible language. I also think that it would make those here who want an object-oriented variant of pb much happier, as this would make coding in such a way possible.

Re: More flexible syntax

Posted: Mon Jun 04, 2012 10:43 am
by moogle
Hydrate wrote:I think adding functionality like this would make Purebasic a significantly more flexible language. I also think that it would make those here who want an object-oriented variant of pb much happier, as this would make coding in such a way possible.
Which is why it will never happen, and probably never be heard.

If you want something here and it's not on a 'todo' list, planned or it's to do with OOP then you gotta do it yourself unfortunately :)

Re: More flexible syntax

Posted: Mon Jun 04, 2012 11:21 am
by xorc1zt
something like namespace would be great

Code: Select all

//c++ namespace
namespace hello1 
{
	char * hello = "hello";
	int number = 25;

	void printhello () 
	{
		printf("%s\n", hello);
	}
}

namespace hello2 
{
	char * hello = "hello 2";
	int number = 15;
	
	void printhello () 
	{
		printf("%s\n", hello);
	}
}

int _tmain(int argc, _TCHAR* argv[])
{
	{
		using namespace hello1;
		printhello();
		printf("%i\n", 35+number);
	}
	

	{
		using namespace hello2;
		printhello();
		printf("%i\n", 35+number);
	}

	printf("\n\n *** press any key to exit ***");
	getchar();

	return 0;
}