ti.teg.tnod.I Posted November 5, 2011 Share Posted November 5, 2011 Basically I want something like this to work: program New; type foo = record bar: procedure(); end; var oof: foo; procedure rab(test: String); begin WriteLn(test); end; begin oof.bar := @rab('Hello World'); oof.bar; end. That returns the error "Type mismatch". My question is: What type is it returning? That would output "Hello World". The python implementation of this would be: def rab(test): print test oofbar = lambda: rab('Hello World') oofbar() A more advanced example of lambda use can be found here. This makes it so I don't need to have multiple functions/procedures when I'm storing them into variables for later, static use (Cannot pass parameters without hacks). Quote Link to comment Share on other sites More sharing options...
Wanted Posted November 5, 2011 Share Posted November 5, 2011 Don't think this is possible. Maybe in titan though.. Quote Link to comment Share on other sites More sharing options...
KingKong Posted November 5, 2011 Share Posted November 5, 2011 (edited) Uh, are you trying to do this? [scar] program New; type foo = record bar: String; end; var oof: foo; function rab(test: String): String; begin WriteLn(test); Result := test; end; begin oof.bar := rab('Hello World'); writeln(oof.bar); end. [/scar] Its kinda difficult to emulate what python does in scar because they both are pretty much opposite to each other(in terms of the way code is written/executed) Edited November 5, 2011 by KingKong Quote Link to comment Share on other sites More sharing options...
ti.teg.tnod.I Posted November 5, 2011 Author Share Posted November 5, 2011 Uh, are you trying to do this?[scar] program New; type foo = record bar: String; end; var oof: foo; function rab(test: String): String; begin WriteLn(test); Result := test; end; begin oof.bar := rab('Hello World'); writeln(oof.bar); end. [/scar] Its kinda difficult to emulate what python does in scar because they both are pretty much opposite to each other(in terms of the way code is written/executed) No, that's storing a string. Also I don't see what makes python the opposite of SCAR at all actually ... Don't think this is possible. Maybe in titan though.. Damn, oh well. I just figured "Type mismatch" implied it was actually returning a usable type. Is there any way to check the type of an object? Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 5, 2011 Share Posted November 5, 2011 That's not possible anywhere, that's not part of Pascal or Delphi syntax Quote Link to comment Share on other sites More sharing options...
nielsie95 Posted November 5, 2011 Share Posted November 5, 2011 In the newer Delphi versions you can accomplish something similar using anonymous methods and variable binding: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/anonymousmethods_xml.html Not possible in SCAR, though. Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 5, 2011 Share Posted November 5, 2011 In the newer Delphi versions you can accomplish something similar using anonymous methods and variable binding: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/anonymousmethods_xml.htmlNot possible in SCAR, though. Well yes, the method part, but as far as I'm aware you can't set parameters in advance? Quote Link to comment Share on other sites More sharing options...
ti.teg.tnod.I Posted November 5, 2011 Author Share Posted November 5, 2011 (edited) Well yes, the method part, but as far as I'm aware you can't set parameters in advance? It's more like an object that calls the function with it's own parameters ... So when you call the function, you're actually calling a lambda object, that calls the function, and the lambda object fills in the parameter. So you're not actualy "presetting" the parameter, I guess it was poor choice of wording on my part. Edit: Does this solve anything? http://delphisorcery.blogspot.com/2011/05/lambdas-and-expression-trees-in-delphi.html Edited November 5, 2011 by ti.teg.tnod.I Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 6, 2011 Share Posted November 6, 2011 Well, in any case... You can't do this in Divi and at the moment not in Titan either. Quote Link to comment Share on other sites More sharing options...
ti.teg.tnod.I Posted November 7, 2011 Author Share Posted November 7, 2011 Well, in any case... You can't do this in Divi and at the moment not in Titan either. Ah okay. I hope to see this as a future feature . Quote Link to comment Share on other sites More sharing options...