Page 1 of 1
Getting a list of keywords
Posted: Friday 11th November 2022 12:21pm
by Median Joe
I would like to print a list of all keywords, and according to the
docs there is this function :
System.Keywords (gb.eval)
However, not sure how to use it. I guess I need to declare an array and write a loop, but all my attempts thus far have generated errors. Could someone kindly point me in the right direction?
Thanks!
Re: Getting a list of keywords
Posted: Friday 11th November 2022 12:49pm
by vuott
Hello,
you can use
FOR...EACH...NEXT cycle:
Public Sub Main()
Dim s As String
For Each s In System.Keywords
Print s
Next
End
Re: Getting a list of keywords
Posted: Friday 11th November 2022 1:15pm
by Median Joe
Thanks vuott,
I haven't quite got my head around how the Gambas object system works and was using the wrong syntax. I've always avoided OO languages until now and have only a hazy grasp of how OOP works, and all languages seem to implement it slightly differently.
Re: Getting a list of keywords
Posted: Friday 11th November 2022 3:31pm
by vuott
Re: Getting a list of keywords
Posted: Friday 11th November 2022 5:29pm
by Median Joe
Thanks for the links. I have started reading Gerry's book which is very good (thanks Gerry!), but I would prefer something more systematic. A Beginner's Guide to Gambas by John Rittinghouse is more comprehensive but it's pretty old. Anyone read it? I don't want to have to unlearn anything and there's a review on Amazon which says it's useless because it's mostly about version 2. Are newer versions of Gambas generally backwards compatible with older versions?
Re: Getting a list of keywords
Posted: Friday 11th November 2022 5:57pm
by BruceSteers
Median Joe wrote: ↑Friday 11th November 2022 1:15pm
Thanks vuott,
I haven't quite got my head around how the Gambas object system works and was using the wrong syntax. I've always avoided OO languages until now and have only a hazy grasp of how OOP works, and all languages seem to implement it slightly differently.
OOP rocks
you can do the same print out like this..
Print System.Keywords.Sort().Join("\n")
System.Keywords returns a String[] array so i use Sort() on that
Sort returns a sorted String[] array so i use Join("\n") on that to join the items with a newline so a single string.
Note: Keywords is a "property" and Sort() and Join() are functions so no brackets needed for Keywords but needed for Sort() and Join()
After typing a Keyword/function()/method()/property/etc then pressing the dot . the autocomplete shows all the properties/methods available.
This has been pretty much all the documentation I ever needed. I find it's kind of "learn as you go"
Re: Getting a list of keywords
Posted: Saturday 12th November 2022 8:24am
by Median Joe
BruceSteers wrote: ↑Friday 11th November 2022 5:57pm
OOP rocks
All criticism of OOP (and there is a lot of it) seems to revolve around knowing when it's a appropriate to use it. It's a good fit for GUI, but maybe not other applications, like merging files or doing calculations for example. At least Gambas doesn't force OOP on you in all situations, as Java seems to.
Yes the built-in documentation is very good.