RSS/Atom feed Twitter
Site is read-only, email is disabled

procedure overloading in scheme / script-fu

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

3 of 3 messages available
Toggle history

Please log in to manage your subscriptions.

procedure overloading in scheme / script-fu Gary Aitken 18 Sep 22:42
  procedure overloading in scheme / script-fu paynekj 19 Sep 13:39
  procedure overloading in scheme / script-fu Kevin Cozens 19 Sep 14:53
Gary Aitken
2012-09-18 22:42:13 UTC (over 12 years ago)

procedure overloading in scheme / script-fu

I assumed from the scheme manual that procedure-overloading (in the form of different numbers of arguments) was permitted, since, for example, there are two versions of string->number. However, I can't seem to get it to work. Anything special one needs to do to overload?

If you take the following code and run it in the script-fu console, it works; but replacing all occurrances of "foo2" with "foo" gets into an infinite loop (I guess; it never returns, in any case). Is this just a user-error mistake,
or is there something different needed to overload a procedure definition? I realize the two arg definition had to appear before the one arg definition which used it; if the order is wrong I get the wrong # args error, which makes sense.

(define (foo2 arg1 arg2) (string-append arg1 arg2))

(define (foo arg1) (foo2 arg1 "def")) (foo "abc")
foo2foo"abcdef"

Thanks,

Gary

2012-09-19 13:39:03 UTC (over 12 years ago)
postings
16

procedure overloading in scheme / script-fu

Can you point me to the scheme manual that talks about overloading please.

As you are talking about variable numbers of arguments, this article seems to explain how it works: http://www.math.grin.edu/~stone/courses/scheme/readings/variable-arity.xhtml

And in your example, by replacing foo2 with foo you end up with a second definition of foo which replaces the first, and then calls itself recursively when used - hence your infinite loop.

Kevin Cozens
2012-09-19 14:53:11 UTC (over 12 years ago)

procedure overloading in scheme / script-fu

On 12-09-18 06:42 PM, Gary Aitken wrote:

I assumed from the scheme manual that procedure-overloading (in the form of different numbers of arguments) was permitted, since, for example, there are two versions of string->number.

Scheme is not an OOP language so it does not support procedure overloading. If you look closely, you will see that string->number and number->string can take an optional parameter, a radix to use during the conversion. The optional radix parameter is not currently supported for either string->number or number->string.

Code to add support for the radix was supplied to the TinyScheme project and is currently being reviewed so radix support may be added soon to Script-Fu.

If you take the following code and run it in the script-fu console, it works; but replacing all occurrances of "foo2" with "foo" gets into an infinite loop (I guess; it never returns, in any case).

If you changed all foo2 to foo, then foo continually calls itself and the console will appear to hang.