lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 10/1/23 15:19, Родион Горковенко wrote:
Probably you'd better start with examples of "script in natural language".

Natural language is a vague thing and it is difficult to reach a vague
goal. You probably rather aim to parse something which _looks like_
natural language but isn't it.

Let me give an example of the main idea I want to create as a proof of concept using Lua.
Let's prepare first some functions for later use:

> function let_x_be(val) x = tonumber(val) end
> function let_y_be(val) y = tonumber(val) end
> function let_z_be_sum_of_x_and_y ()  z = x + y end

With this functions defined, Lua already allows to write following code:

> let_x_be '0xff' _=',' let_y_be '15' _='and' let_z_be_sum_of_x_and_y''

The result of the code above is:
> x
255
> y
15
> z
270

I suppose that making in Lua possible what is possible in Python where it is not necessary to give a string literal a name should not brake anything and be not that hard to implement making then following possible:

> let_x_be '0xff' ',' let_y_be '15' 'and' let_z_be_sum_of_x_and_y''

Implementing function calls accepting beside string literals also numbers will then allow:

> let_x_be 0xff ',' let_y_be 15 'and' let_z_be_sum_of_x_and_y''

Going a step further allowing a dot and a comma treating them as whitespace if not in appropriate context and allowing function calls without passing any parameter will allow:

> Let_x_be 0xff 'and' let_y_be 15 . 'With x and y values set respectively to 255 and 15', let_z_be_sum_of_x_and_y .

This would turn Lua into a programming language making it possible to write code in way which reads like natural language sentences making a very interesting programming language out of it and the only one of this kind among all the others programming languages out there.

Feel free to visit the repository for a bit more background of what I would like to use Textadept and Lua for https://github.com/oOosys/oOo (being in very early stage of progress, but already with quite expressive and powerful guidelines). Sorry, but I am not yet fully clear if functions should be able to take arguments or not and if yes in which form ...

Claudio





On Sun, Oct 1, 2023 at 2:42 PM Claudio Grondi <claudio.grondi@freenet.de> wrote:

Lua would require some minor changes only, which if I am not mistaken
won't break any past code and should be relatively easy to implement, in
order to support natural language texts as valid script code.

May someone help me to provide proof of the concept explaining where and
how to modify Lua C-code in order to:

1.    allow ASCII values 0x02 (Start of Text) and 0x03 (End of Text) to
be used in script code and interpreted respectively as `[[` and `]]`

2.    allow function calls by specifying the function name only (without
using braces and without the need of passing a parameter)

3.    extend [_a-zA-z0-9] characters allowed in symbol names with ASCII
value 0x1F (Unit Separator) and `-` which will be treated like [0-9] not
allowed as first symbol name characters

4.    allow usage of unnamed strings (i.e. string literals which can be
specified anywhere in code without the need of assigning them to a
symbol) ignoring them like comments

5.    allow next to `;` also usage of `,` , `.` and `:`

?