A challenge for you
Posted
#1
(In Topic #126)
Guru

These are the Gambas tasks 'solved' http://rosettacode.org/wiki/Category:Gambas
These are the Gambas tasks that need doing http://rosettacode.org…not_implemented_in_Gambas
It can be fun. Give it a go!
Posted
Regular

Posted
Guru

You know you can get permalinks by clicking the "Gist" button
I am aware of this but it was hard enough getting the link in. Every time I had to prove I was not a robot! I have completed 142 of the challenges of which 91 will run in the 'Playground' so it took some time to add the link to these anyway.
Posted
Regular

Posted
Guru

The 'A's are done e.g. http://rosettacode.org/wiki/Align_columns#Gambas
Posted
Regular

Posted
Regular

sjsepan said
…Is there a concept of a 'Delegate' in Gambas, or a way to pass a pointer to a procedure, and then reference it in the destination to execute it? …
Hi Steve, not sure what you have in mind to do with a pointer, or how this relates to the "Repeat" task.
But would using ByRef do what you wanted to do?
Maybe give us an example (…or write a pseudoCode example).
You may be interested in this: http://gambas.8142.n7.nabble.com/Callback-td6163.html
…and this: http://gambas.8142.n7.nabble.com/ByRef-td18173.html
BTW, for Rosetta Repeat, I just copied the VBA example & tweaked it:-
…but I guess that is not in the spirit of the project.
Posted
Regular

Posted
Regular

Code (gambas)
- ' Gambas class file
- TextBox1.Text = 5
- p1Pointer = pPointer
- h1Memory = hMemory
- p2Pointer = pPointer
- h2Memory = hMemory
- Label1.Text = ReadValue(p2Pointer)
It allocates some memory just big enough for an integer, then sets an initial value…just need a form, 2 buttons, a textbox & a label.
Posted
Regular

The example of pointers is appreciated nonetheless – didn't see any robust examples elsewhere yet. Thanks!
I did try ByRef the other day in the hope it would make a difference, but no.
Delegates are an interesting and powerful feature, so I hope something like it makes it into Gambas some day. As this was only for one of the RosettaCode task candidates, its not a showstopper, but its a good way to learn whether I know Gambas as well as I 'd like to think I do. ;-) Still have a way to go…
Steve
PS – just saw the Nabble links. Looks like tobias-47 was on a similar quest. Will read through it and see what was discussed – Thanks!!
stevedee said
Just for completeness, I think this is a valid (but crude) example of passing pointers;
UPDATE: well the Nabble links got me far enoguh to submit a Gambas item, but with caveats noted in the description:
http://rosettacode.org/wiki/Repeat#Gambas
In case they flag it for not closely enough meeting the specs, I am posting the code here too:
Code (gambas)
- 'Note: Gambas (3.14.0) cannot perform this task as specified, as it does not have delegates, and pointers do not seem to work with procedures.
- 'What does work is using Object.Call, which is intended for executing procedures from external libraries.
- 'However the accepting procedure must refer to the object containing the procedure, and refer to the procedure by a String name.
- 'In this case, the current module/class reference (Me) is used, but the String name must be passed.
- 'This arrangement will only work within the same module/class.
- 'It may be possible to pass the parent reference to a method (taking 3 parameters) in another class if the named procedure is Public.
- 'The empty array ([]) in Object.Call represent a procedure without parameters, which are not an explicit requirement for this Task, but might require another parameter to the accepting procedure.
- RepeatIt("RepeatableOne", 2)
- RepeatIt("RepeatableTwo", 3)
- 'Cannot pass procedure pointer in Gambas; must pass procedure name and use Object.Call()
- Print "RepeatableOne"
- Print "RepeatableTwo"
1 guest and 0 members have just viewed this.


