syntax-rules

How to control order of Scheme macro expansion?

夙愿已清 提交于 2019-12-11 02:35:57
问题 I'm working with the Racket macro extension syntax-id-rules , that some other Scheme implementations provide under the name identifier-syntax . These let you specify macro expansions that will happen even when the defined identifier isn't in head position. So for example: (define hidden #f) (define-syntax proxy (syntax-id-rules (set!) [(set! proxy v) (set! hidden v)] [proxy hidden])) will set up the identifier proxy to be a proxy for hidden . This is a useless example, but it illustrates the

Implicit currying in Scheme with syntax-rules?

前提是你 提交于 2019-12-06 02:29:54
问题 Jeffrey Meunier has an implicit Curry macro here, which uses defmacro. I was wondering if someone has ever written this with syntax-rules? 回答1: There are a number of curry implementations for Scheme -- none can be as elegant as Haskell, since there functions are always unary functions, so everything can be curried. (But this can of course be implemented in a sufficiently powerful Scheme like Racket.) As for the macro that you've dug up -- it's a pretty bad one: not only does it use an

How can I closely achieve ?: from C++/C# in Python?

给你一囗甜甜゛ 提交于 2019-12-05 19:50:31
问题 In C# I could easily write the following: string stringValue = string.IsNullOrEmpty( otherString ) ? defaultString : otherString; Is there a quick way of doing the same thing in Python or am I stuck with an 'if' statement? 回答1: In Python 2.5, there is A if C else B which behaves a lot like ?: in C. However, it's frowned upon for two reasons: readability, and the fact that there's usually a simpler way to approach the problem. For instance, in your case: stringValue = otherString or

Implicit currying in Scheme with syntax-rules?

耗尽温柔 提交于 2019-12-04 07:45:41
Jeffrey Meunier has an implicit Curry macro here , which uses defmacro. I was wondering if someone has ever written this with syntax-rules? There are a number of curry implementations for Scheme -- none can be as elegant as Haskell, since there functions are always unary functions, so everything can be curried. (But this can of course be implemented in a sufficiently powerful Scheme like Racket .) As for the macro that you've dug up -- it's a pretty bad one: not only does it use an unhygienic macro, it's also calling eval explicitly, and relies on an implementation of environments etc. But it

How can I closely achieve ?: from C++/C# in Python?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 04:00:41
In C# I could easily write the following: string stringValue = string.IsNullOrEmpty( otherString ) ? defaultString : otherString; Is there a quick way of doing the same thing in Python or am I stuck with an 'if' statement? In Python 2.5, there is A if C else B which behaves a lot like ?: in C. However, it's frowned upon for two reasons: readability, and the fact that there's usually a simpler way to approach the problem. For instance, in your case: stringValue = otherString or defaultString @Dan if otherString: stringValue = otherString else: stringValue = defaultString This type of code is