public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Disambiguate method from function
@ 2020-12-16  8:49 Duncan Mak
  2020-12-16 10:59 ` Per Bothner
  0 siblings, 1 reply; 2+ messages in thread
From: Duncan Mak @ 2020-12-16  8:49 UTC (permalink / raw)
  To: kawa mailing list

Hello all,

I have some code like this,

(define-simple-class Person ()
>   ((hello)
>    (hello "Calling from method")))
>


(define (hello message) (format #t "~A~%" message))
>


(hello "Calling from function")
> ((Person):hello)


This doesn't work because I think it gets confused between hello the method
and hello the function:

test.scm:3:4: call to 'hello' has too many arguments (1; must be 0)


I could of course resolve this by renaming 'hello' the function to
something like 'hello*', but is there another way to disambiguate the two?

-- 
Duncan.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Disambiguate method from function
  2020-12-16  8:49 Disambiguate method from function Duncan Mak
@ 2020-12-16 10:59 ` Per Bothner
  0 siblings, 0 replies; 2+ messages in thread
From: Per Bothner @ 2020-12-16 10:59 UTC (permalink / raw)
  To: Duncan Mak, kawa mailing list

On 12/16/20 12:49 AM, Duncan Mak via Kawa wrote:
> This doesn't work because I think it gets confused between hello the method
> and hello the function:
> 
> test.scm:3:4: call to 'hello' has too many arguments (1; must be 0)
> 
> 
> I could of course resolve this by renaming 'hello' the function to
> something like 'hello*', but is there another way to disambiguate the two?

Nothing I can think of to explicitly disambiguate.  (I tried some.)

I suggest using an alias:

(define-simple-class Person ()
   ((hello)
    (%hello "Calling from method")))

(define (hello message) (format #t "~A~%" message))
(define-alias %hello hello)

(hello "Calling from function")
((Person):hello)

-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-16 10:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-16  8:49 Disambiguate method from function Duncan Mak
2020-12-16 10:59 ` Per Bothner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).