Home > Archive > Dylan > October 2005 > Using apply on make()
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using apply on make()
|
|
| Mike Austin 2005-10-15, 3:56 am |
| I'm still learning Dylan, and I was trying different ways to instantiate a
class if you had the name of the class as a string. I came up with this, but
it doesn't work. Any suggestions?
define method make-from-string (string == "<view>", #rest args) => ()
//apply (make, add (args, <view> ));
apply (make, concatenate (list(<view> ), args));
end;
I could be totally about how args works but it looks right from
example Dylan code.
Thanks,
Mike
| |
| Mike Austin 2005-10-15, 7:55 am |
| Mike Austin wrote:
> I'm still learning Dylan, and I was trying different ways to instantiate
> a class if you had the name of the class as a string. I came up with
> this, but it doesn't work. Any suggestions?
>
> define method make-from-string (string == "<view>", #rest args) => ()
> //apply (make, add (args, <view> ));
> apply (make, concatenate (list(<view> ), args));
> end;
Well, it would help if I had a return value. :)
define method make-from-string (string == #"<view>", #rest init-args, #key)
=> (object :: <object> )
apply (make, <view>, args);
end;
It seems I can't define a make() for strings because the method is not
congruent. It has the same number of arguments, does Dylan treat make() specially?
Thanks,
Mike
| |
| Daniel Brockman 2005-10-15, 6:56 pm |
| Mike,
> It seems I can't define a make() for strings because the
> method is not congruent. It has the same number of
> arguments, does Dylan treat make() specially?
The first argument to the generic function `make' must be an
instance of <class>, because that's how `make' is defined.
Since strings are not classes, you can't add a method that
looks like `make(<string>, ...)'.
I hope this helps,
--
Daniel Brockman <daniel@brockman.se>
| |
| Mike Austin 2005-10-15, 9:55 pm |
| Daniel Brockman wrote:
> Mike,
>
>
>
>
> The first argument to the generic function `make' must be an
> instance of <class>, because that's how `make' is defined.
> Since strings are not classes, you can't add a method that
> looks like `make(<string>, ...)'.
>
>
> I hope this helps,
Oh, you mean the generic function make() is specialized already? I'm still
learning how to use multi-methods and Dylan in general.
Thanks,
Mike
| |
|
|
| chris.double@gmail.com 2005-10-17, 6:57 pm |
| If you look at the DRM entry for 'make' you'll see that is defined to
take an argument which is an instance of <type>:
http://www.gwydiondylan.org/books/drm/drm_98.html
So any methods added to it must at least derive from <type>. <class>
derives from type and you'll see on that page tha a method exists
specialised for <class>.
Trying to add a method specialized on a specific string won't work
since that string is derived from <string>, which does not derive from
<type> at all.
Hope that helps,
Chris.
|
|
|
|
|