hyln9 / ikarus

Optimizing incremental native-code compiler for R6RS scheme. This is a forked repository.
https://launchpad.net/ikarus
Other
5 stars 0 forks source link

Request: syntax parameters #240

Closed hyln9 closed 10 years ago

hyln9 commented 10 years ago

Hi

I wonder if it is possible to provide something like PLT's syntax parameters [1].

Or is there perhaps a portable way to implement it?

Thanks

leppie

[1] http://docs.plt-scheme.org/reference/stxparam.html

Launchpad Details: #LP404557 leppie - 2009-07-25 10:10:00 -0400

hyln9 commented 10 years ago

On Jul 25, 2009, at 5:10 PM, leppie wrote:

Or is there perhaps a portable way to implement it?

There are some use cases that can be implemented portably. What are you trying to do?

Aziz,,,

Launchpad Details: #LPC Abdulaziz Ghuloum - 2009-07-26 02:24:48 -0400

hyln9 commented 10 years ago

Hi

I would like to change all appearances of case-lambda appearing in the body of a macro called define/contract with case/contract, hygienically.

You can see my experimentation here [1].

For every version (except the first broken one, and the last limited one), all attempts have many problems. Ideally it would be the same as the 2nd last version, but without the issues [2].

The last version is good enough for my use now, but I am interested in making a bit more generic. Eg allow case-lambda not just in that specified position.

Cheers

leppie

[1] http://paste.lisp.org/display/84169

[2]

(define/contract foo (lambda () '(case-lambda [x x]))) (foo) (case/contract (x x))

Launchpad Details: #LPC leppie - 2009-07-26 04:52:32 -0400

hyln9 commented 10 years ago

On Jul 26, 2009, at 11:52 AM, leppie wrote:

I would like to change all appearances of case-lambda appearing in the body of a macro called define/contract with case/contract,
hygienically.

I don't think syntax parameters would work here since case-lambda would not be bound to a syntax parameter. (IIUC, you can only syntax-parameterize identifiers that are bound using define-syntax-parameter and not any plain-old binding, right?)

Aziz,,,

Launchpad Details: #LPC Abdulaziz Ghuloum - 2009-07-26 05:07:26 -0400

hyln9 commented 10 years ago

Mmm, I thought that might a problem.

I dont know how PLT handles it. Perhaps they ARE defined as syntax-parameters.

Any ideas, on how (and if possible) to solve my 'problem' ?

Thanks

leppie

Launchpad Details: #LPC leppie - 2009-07-26 05:31:44 -0400

hyln9 commented 10 years ago

On Jul 26, 2009, at 12:31 PM, leppie wrote:

Mmm, I thought that might a problem.

I dont know how PLT handles it. Perhaps they ARE defined as syntax- parameters.

I could be wrong but I don't think so. But even if they are, I don't see how that solves your problem. Syntax-parameters/fluid-let-syntax are pretty serious since they change the meaning of the identifiers (in pretty much the same way fluid-let, set!s in dynamic-wind, and parameterize do) and that affects ALL occurrences of that identifier. E.g., if any form, say define-record-type, expands to a case-lambda, then that too will be affected by the fluid binding. I don't think you want that.

Any ideas, on how (and if possible) to solve my 'problem' ?

But I don't know what you're trying to do really. All you said was:

On Jul 26, 2009, at 11:52 AM, leppie wrote:

I would like to change all appearances of case-lambda appearing in
the body of a macro called define/contract with case/contract,
hygienically.

which doesn't make much sense ("I want to capture it hygienically" is an oxymoron).

And the link you provided lists a bunch of macros, each doing something very different, so, I don't know exactly what you're trying to
accomplish.

I think you need to formulate your problem clearly first. :-)

Aziz,,,

Launchpad Details: #LPC Abdulaziz Ghuloum - 2009-07-26 11:38:47 -0400

hyln9 commented 10 years ago

I think you need to formulate your problem clearly first. :-)

Let me try again :)

I only want to change case-lambda into case/contract within the 'body' of define/contract. Hence ONLY the input needs and must be transformed. Later appearances of case-lambda in the expansion of define/contract must NOT be affected. This is where I am not sure if syntax-parameters will work, IIUC it will replace in the expansion too. I do not want that at all.

This must also be hygienic (not sure where you get capture from).

Some examples:

  1. (define/contract foo (case-lambda [x x])) -> (define foo (case/contract [x x]))
  2. (define/contract foo (let ((x x)) (case-lambda [x x]))) -> (define foo (let ((x x)) (case/contract [x x])))
  3. (define/contract foo (lambda x '(case-lambda [x x]))) -> (define foo (lambda x '(case-lambda [x x])))

For hygiene: (import (rnrs) (rename case-lambda cl)) (define/contract foo (cl [x x])) -> (define foo (case/contract [x x]))

Given the last 2 'annotations' on the previously mentioned page (3,4) [1].

  1. Fails on example 3
  2. Fails on example 2

None of the examples must fail.

Does this explain it a bit better?

Thanks

leppie

[1] http://paste.lisp.org/display/84169

Launchpad Details: #LPC leppie - 2009-07-27 02:50:41 -0400

hyln9 commented 10 years ago

On Jul 27, 2009, at 9:50 AM, leppie wrote:

I only want to change case-lambda into case/contract within the 'body' of define/contract. Hence ONLY the input needs and must be
transformed. Later appearances of case-lambda in the expansion of define/contract must NOT be affected. This is where I am not sure if syntax-parameters will work, IIUC it will replace in the expansion too. I do not want
that at all.

Right. So, why the feature request? :-)

This must also be hygienic (not sure where you get capture from).

Some examples:

  1. (define/contract foo (case-lambda [x x])) -> (define foo (case/ contract [x x]))
  2. (define/contract foo (let ((x x)) (case-lambda [x x]))) ->
    (define foo (let ((x x)) (case/contract [x x])))
  3. (define/contract foo (lambda x '(case-lambda [x x]))) -> (define
    foo (lambda x '(case-lambda [x x])))

For hygiene: (import (rnrs) (rename case-lambda cl)) (define/contract foo (cl [x x])) -> (define foo (case/contract [x
x]))

Given the last 2 'annotations' on the previously mentioned page (3,4) [1].

  1. Fails on example 3
  2. Fails on example 2

None of the examples must fail.

Does this explain it a bit better?

Yes. The short answer is: it's not doable. You need to change the
problem a little.

What you can do is have a new macro, call it case-lambda*, that
expands to case/contract if it appears inside define/contract, and
expands to case-lambda otherwise. This is doable, but I don't know
if it meets your needs. If you need help, forward to ikarus-users.

Aziz,,,

Launchpad Details: #LPC Abdulaziz Ghuloum - 2009-07-27 08:43:59 -0400

hyln9 commented 10 years ago

On Jul 27, 2009, at 3:43 PM, Abdulaziz Ghuloum wrote:

Yes. The short answer is: it's not doable.

Actually, it's doable by identifier fishing. Fishing for identifiers
is not recommended though, so, I still think you should change the
problem. :-)

Aziz,,,

Launchpad Details: #LPC Abdulaziz Ghuloum - 2009-07-27 08:49:11 -0400

hyln9 commented 10 years ago

Right. So, why the feature request? :-)

It was so recommended, but perhaps the problem was misunderstood too.

What you can do is have a new macro, call it case-lambda*, that expands to case/contract if it appears inside define/contract, and expands to case-lambda otherwise.

In that case, I could simply use case/contract without even being in a define/contract.

Actually, it's doable by identifier fishing.

I have no idea what that is, but I'll look it up :)

If you need help, forward to ikarus-users.

If I do need more help, I will do so.

Thanks

leppie

Launchpad Details: #LPC leppie - 2009-07-27 11:35:09 -0400

hyln9 commented 10 years ago

On Jul 27, 2009, at 6:35 PM, leppie wrote:

Right. So, why the feature request? :-)

It was so recommended, but perhaps the problem was misunderstood too.

Perhaps.

What you can do is have a new macro, call it case-lambda*, that expands to case/contract if it appears inside define/contract, and expands to case-lambda otherwise.

In that case, I could simply use case/contract without even being in a define/contract.

Right. I now know what you're trying to accomplish, but I don't know why.

Actually, it's doable by identifier fishing.

I have no idea what that is, but I'll look it up :)

Basically, search the body for occurrences of case-lambda, and once you have the entire set, bind them to something else. The technique is due to Al Petrofsky (sometimes called `The Petrofsky Extractor').

Aziz,,,

Launchpad Details: #LPC Abdulaziz Ghuloum - 2009-07-27 16:28:12 -0400

hyln9 commented 10 years ago

I added define-fluid-syntax and fixed fluid-let-syntax in revision 1830 (just in case it's needed in the future, though I doubt it has great utility anyways given its semantics).

Launchpad Details: #LPC Abdulaziz Ghuloum - 2009-07-28 15:26:27 -0400

hyln9 commented 10 years ago

Thanks :)

I assume fluid-syntax is similar to syntax parameters then?

just in case it's needed in the future, though I doubt it has great utility anyways given its semantics

I do use it via define-integrable for my fixnum library, as my compiler does not inline code very well. :-)

Launchpad Details: #LPC leppie - 2009-07-29 11:43:41 -0400