-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I like to request some features to make YueScript easier to copy code and use with AI assistant code like ChatGPT and Github Copilot, Tabnine! #152
Comments
Yes, I can start with supporting Lua syntax right in Yuescript. Maybe just make f = (tb)->
sum = 0
for item in *tb
sum += item
lua
local data = {
valueA = 123,
valueB = "ABC"
}
function tb:print()
for i, v in ipairs(self) do
print(i, v)
end
end
end
print "back to Yue"
sum
|
Thanks for your consideration! It would be nice if Yue can use But I don't think adding inline Python syntax support is necessary and too much work need to implement and it don't benefit much when Python syntax similar but not better Yue when runtime Python too different to lua. I agree that use -- file: utility.lua
local function trim(s)
return strip(s, " ")
end
local function strip(s, char)
return s:gsub(s, "^" .. char .. "+", ""):gsub(s, char .. "+$", "")
end
local utility = {
trim = trim,
strip = strip
}
-- file: test.lua
print(utility.trim(" abc ")) -- [ERROR] attempt to call a nil value (global 'strip') Thank you and regards! |
Got a little problem for list syntax with with tb
-- this is a valid indexing syntax inside a "with" block
-- so we have to use [1,] as a list with only one element
print [1]
-- here represents closed intervals for range comparison
if value in [1, 10]
print "1 <= value and value <= 10"
-- here for list values checking, support syntax of [20, 30] as list literal may lead to confusion
elseif value in {20, 30}
print "value is 20 or 30" |
I think the in-range syntax is not easy read and to much confusion when use bracket and parenthesis together a = 5
if a in <=1, 10>=
print "a is in range from 1 to 10"
if a not in <=1, 10>=
print "a is not in range from 1 to 10"
if a in <0, 11>
print "a is between 0 and 11 with open intervals"
if a in (1, 3, 5, 7)
print "checking equality with discrete values"
And the Thank and regards! |
The in-range symbols were introduced from mathematics symbols. Yes it seems to be weird for a programing language. I just picked them because they cost less character to type but I got that it is requiring more familiarity with mathematics writing. Maybe a = 5
if a in <=1, 10=>
print "a is in range from 1 to 10"
if a not in <=1, 10=>
print "a is not in range from 1 to 10"
if a in <0, 11>
print "a is between 0 and 11 with open intervals"
if a in (1, 3, 5, 7)
print "checking equality with discrete values" or a = 5
if 1 <= a <= 10
print "a is in range from 1 to 10"
if not (1 <= a <= 10)
print "a is not in range from 1 to 10"
if 0 < a < 11
print "a is between 0 and 11 with open intervals"
if a in (1, 3, 5, 7)
print "checking equality with discrete values" |
Operator chaining like the 2nd part is the most natural and already exists in other languages. |
For the |
Well x = 2
res = 1 < x < 3 # True in Python, Error in Lua/Yue.
print(res) Lua/Yue only work with About AI, large model AI don't need to know about language at all, they know about patterns in your text and what it maybe meaning (or not at all). Then they generate some random text for us. Only a I use Github-copilot not because of how smart it is but because it is faster to edit something than write the code from zero. It just like how we choice to not code in Well... AI is just a tool. The same as code editor we use. AI suggestions is no different with editor autocomplete. In the end it total depends on us to choice what code we write, but if we can make it work better with Yue, then why not? I love Yue, and I want to see it continue evol and adapt. |
Added chaining comparisons and list syntax list_with_only_one_element = [1,]
tb = [
1
2
3
abc: 123 -- will report error here
]
[a = 1. b = 2] = tab_to_be_destructured |
There's no need to homogenize languages here. One consistent syntax is better than programmers being able to do different things when it suits them. Nearly all suggestions here make the language more complicated syntax wise for no reason other than to suit someone using AI tools that don't actually understand the language and therefore serve no benefit. |
Uhm... of course there will be no homogenize languages here because Lus is an oddball one, so is Yue. But in other words, Yue is a language that bundles a lot of sweet syntax sugar for Lua. Because of that there is a limit for what Yue can do about runtime. But Yue can continue to improve by further adopting and improving its syntax while cafefully considering the pro/con. Yue is not a popular language, so not many people will care to give an opinion about it. While I can perfectly write any Lua codes if I must/want to. But I chose to use Yue because it is fast, expressive and concise. I love Yue, see the problems with it and try to give some suggestions to make it more pleasing and faster to work with. It sure benefits me, then maybe it can benefit other people too. I am not a fool who uses things he doesn't understand. I fully understand Lua/Yue but I work a lot with JS, Python so my head screams painful when read/write the same And I try my best to give opinions about syntax wise only, to not ask for a weird feature that just complies to a Lua code function that must be implemented by the user. |
Is this not something that can be made better for you specifically by using macros?
Nothing wrong with that at all. That's what I'm doing here, too. I use Yue heavily for personal projects and scripts, just like you. I'm giving my personal opinion.
I didn't say you are a fool, nor that you don't understand it. I said the tools you are using do not understand it. That is the source of the problem, not the language. Why not improve the tools you use to better utilize the language? None of these changes will improve your actual editing experience.
As mentioned above, nothing wrong with that. I'm doing the same, just voicing my opinion. One last thing on your previous comment:
Don't commit broken code :) This is PEBKAC, not the language's fault. |
As a maintainer of Yuescript project. The more user opinions given to me the better dev decisions I can make to do a better maintenance or improvements. I appreciate your heavy usages @chrsm with Yuescript project. So that maybe more specific usage case with details can better convince me there are better ways to dev more features or bug fixes. So back to this thread. Do you think list table syntax like |
Since we are just sharing a pretty small community. I think I can push things to go faster once I got vacant time, and actually try various ideas to see if they will work out. |
I very like the syntax About And I use my custom Yue code highlight and some custom tools for Yue, because of that, maintaining it with syntax like Thanks and regards! |
@GokuHiki I got your point, the in range expr was removed and being replaced by chaining comparison operators. And list literal with [ ] is now available. You may also have a try now. |
I thought a bit about the square bracket list syntax, some ideas:
|
I like the list table syntax of
Chained comparisons are fine. I'm a bit "old" so I tend to think of
I didn't see this comment until now. The main reason I find the macro-to-Lua more useful is simply that the generated Lua can be modified programmatically. I am not sure of the use case for mixing the two directly. Is there something that only Lua can do that Yue can't? If not, I'd just translate the Lua bits to Yue rather than mixing them. In the case of, say, a class, you'd need to know what the generated code looks like to reference generated things anyway, right? Which will likely be more annoying for those that use the feature.
Is this highlight/tooling public? I only use the stock |
I use a very custom pipeline with the flow: a custom yue script -> transform to vanilla yue -> to lua code -> re-add only comment docs string, blank lines and reformat lua code + trackback yue line debug info -> lint lua code with luacheck + selene -> trackback problems to yue code and output errors to VSCode. I must use a custom syntax highlight solution because of it. It is just a bundle of mismatched codes that combines many tools and scripts of some languages and relies heavily on regex as a dirty-quick solution for my specific requirements. I know it is not a good practice and easy to break when I write something that is out of normal but... at least, it works for now. |
The use case: Being lazy ;) In terms of what you should do, either just rewrite it if it is small enough, or if not... it's probably already a library which you could just require/import it directly. |
Well...
I use YueScript daily to write tools and script games as a hobby, but I also work in other languages like Python, javascript, C# and GDScript as a dev. I extend use Github Copilot and sometime ChatGPT. The AI really helpful but they just keep suggest with Python or Lua code. It is a chore to convert them back to YueScript. It is the same when I want to 'borrow' codes online.
Then one idea pop into my mind, why not make YueScript more AI and copy friendly by support more Python, Lua or other lanagues common syntax, notation and make it easier to convert code to YueScript. I think it will be a great feature for YueScript and make it more popular.
Here are some I think will be helpful:
Support create list like table with syntax:
arr = []
YueScript only support [] in list comprehension like Python. It is kind of a wasteful syntax and it is like a chore to must convert all [] => {}. Support
[]
make code look better, easier to see, AI Copilot friendly and easier to copy, convert from code of other languages like: Python, javascript, json, GDScript, etc.Support Lua table syntax:
{key = val}
It copies Lua's code table or accepts AI's suggested code without the need to edit it would be nice. And it is a nice style, even GDScript supports it then why won't YueScript support it?
Support declare function style like:
function myfunction(parm1, param2)
orfunc myfunction(parm1, param2)
ordef myfunction(parm1, param2)
would be nice.It is a common syntax in many languages like Python, Lua, GDScript, etc. It looks better than
myfunction = () ->
. Yuescript is very nice but I think that humans and AI prefer it more.I like to write yuescript to make some local tools to process my assets. My OS is Windows, I prefer to use YueScript/Lua over bat/cmd. It would be nice if YueScript supports more template string because
"${exe} #{arg1} #{arg2}"
is not good on Windows: exe ad arg1/arg2 can have space in the path and require quotes with '"'. It would be nice if YueScript supports raw template string like:Add support 'var' keywords like javascript, GDScript: with feature hoisting as JavaScript's default behavior of moving declarations to the top of functions or global scope. It solves the problem of using a variable before it has been declared without need to use
local *
:It is the pain when writing utility scripts that have many functions and depend on each other
Thank you and regards!
The text was updated successfully, but these errors were encountered: