Thursday, January 08, 2009

Fexprs? in Scheme?

“The top level is hopeless.”
     -- Matthew Flatt [1] [2] [3] [4] [5] [6] [7] [8] [9]
Scheme's top level allows for interactive evaluation such as at the REPL, where global definitions can be dynamically evaluated one by one. To allow for forward references, free variables are not a static error at the top level. But global definitions may be macros, and there's no way to know whether a forward reference is eventually going to turn out to be a value binding or a macro binding. So one simple semantics is just to assume that forward references are always value bindings and compile them as such. But then you get unsatisfying interactions like this:
> (define (f) (display (g 42)))
> (define-syntax g (syntax-rules () ((g x) (quote x))))
> (f)
reference to an identifier before its definition: g
It's worse with macro-defining macros. For example, a define/inline form would bind its definition as a macro, but the user could generally treat it as a value binding. But you'd still run into the same problem:
> (define/inline (f) (g 42))
> (define/inline (g n) (add1 n))
> (f)
reference to an identifier before its definition: g
What's in conflict in Scheme is the desire for macros to be a static, compile-time entity and the REPL to allow dynamic, incremental update to the global environment. In fact, the top level seems to be the one place in Scheme where programmers expect behavior something like Lisp's antiquated fexprs. Bear with me...

Imagine if the compiler treated any form (x . s) where x is a top-level variable reference--bound or unbound--as an uninterpreted syntax object waiting to be parsed. Then only when the form is evaluated would x be looked up in the global environment to determine how to compile the form. If x is unbound, it's a dynamic error; if it's a value, it's compiled and evaluated as a function application; if it's a macro, it's macro-expanded, compiled, and evaluated. This would accomodate any sequence of definitions and redefinitions of top-level bindings, either as value bindings, macro bindings, or both. For example:
> (define (foo x) (f x))
> (define (f x) (add1 x))
> (foo 41)
42
> (define-syntax f (syntax-rules () ((f e) (quote e))))
> (foo 41)
x
This has a lot of the similarities to fexprs; it means a function like foo is subject to dynamic reparsing: at one point it calls a function on x and at another point it applies a macro. But whereas with fexprs, any application expression may be dynamically reparsed, here this would only be the case for applications of top-level variables.

Fexprs are bad for two reasons: they make the language hard to compile efficiently and they make programs hard to understand by subjecting the basic program definition to dynamic reinterpretation. To be sure, making Scheme's top-level fexpr-like would make efficient compilation harder. But the top-level is the part of Scheme where programs are dynamically defined. Users are constantly surprised at the behavior of top-level forward references and macro definitions. What they seem to naturally expect is, in some sense, fexprs.

65 comments:

Pascal Costanza said...

Why not just use an interpreter instead of a compiler for interactive development?

Dave Herman said...

That's largely orthogonal; I'm talking about specifying the observable behavior. (Perhaps that's what you mean but then you're begging the question. "Use an interpreter" doth not a semantics make.)

Richard Cobbe said...

Thank you, Dave, for posting this! I've heard lots of people exclaim in disgust that "the top level is hopeless," but they very rarely deign to explain why.

Since the problems with it are subtle and can be explained only after a great deal of thought and experience, explanations like this are valuable to those of us who haven't gone through that process ourselves.

Shiro Kawai said...

"But the top-level is the part of Scheme where programs are dynamically defined."

Not a part of R6RS, anyway. So I guess we can treat toplevel as an ad-hoc utility, much like the debugger interface, instead of a part of rigidly defined "language". If it is only for development-time help for programmers, efficiency may be traded off for users' convenience.
Then dynamic re-compiling seems an acceptable choice to me. (Yes, it complicates implementation, but features that provide users' convenience tends to make implementation complicated in genreral).

Pascal Costanza said...

What I mean with "use an interpreter" is that you can delay the decision whether something is a macro or a function until it is actually called. In such a case, it doesn't matter whether a free reference will eventually refer to a function or a macro, because the decision can be delayed until the very last moment. That's good for interactive development.

Kazimir Majorinc said...

Dave,

related question: why eval see global lexical variables?

(define x 55)
(eval 'x) => 55

is it the same special treatment of top level, or it is natural consequence of something I do not see?

John Cowan said...

But then you get unsatisfying interactions like this:

Unsatisfying it may be in the abstract, but treating undefined references from the top level as variables is a fact of life for anyone who uses a Scheme REPL. Of the 45 Schemes that I test regularly with, all except SCM (and a few that don't support macros) have the same behavior at the REPL. Undefined forward references are treated as variables, and syntax expressions are expanded inline when a procedure invoking them is defined. Attempts to redefine syntax keywords post hoc have no effect on procedure definitions already seen, though they are effective for later procedure definitions. This is the semantics that R7RS-small prescribes for any implementation providing a REPL. (SCM does the expansion lazily, so redefining syntax will be effective if the procedure containing it has never been called.)

John Cowan said...

See also "The Tale of Professor Simpleton and Dr. Hardcase" for an explanation of the general problems with using syntax before defining it.

Unknown said...

Hi...Nice blog. Really very interesting....!!!

Dissertation binding

Unknown said...

Hi...Nice blog. Really very interesting....!!!


Dissertation binding

lucifer1413 said...

Norton.com/setup - Consumers and small businesses are experiencing a new sense of security for over 25 years with Norton. Norton setup downloaded from the norton.com/setup page helps to work and explore the ever-changing digital landscape. Norton makes it as easy to protect and manage your devices while installing an application on your smartphone.

For More Information Visit Our Site: norton.com/setup 

Computer Security said...

Thanks for the information. It's very useful.I really enjoyed your blog. aol-desktop-gold-download

richard said...

Nice Post Very Informative and knowledgeable, Keep doing it
We provide Computer Antivirus Support to Your System, We protect it from from damamging. As we all Know Everything is getting Digital, So Dont You think there is aneed to protect your system.
For Support Visit- mcafee.com/activate
norton.com/setup
norton.com/setup

richard said...

Nice Post with great source of knowledge for all of us. Keep doing this work.
Protect Your System from antivirus attack as bad guy are trying to hack your system. We Provide help and support in computer antivirus software. For help visit us-
norton.com/setup

richard said...

Nice Post with great source of knowledge , keep doing this work
We Need to protect our system from antivirus attack and malware.As everything is getting digitally developed.
mcafee.com/activate

richard said...

Nice Post with great source of knowledge , keep doing this work
Protect your system from antivirus attack and damage
norton.com/setup

primevideo.com/mytv said...

Norton 360 Standard – for 1 gadget with Auto Renewal – gives you incredible layers of security for your associated gadget and online protection. norton.com/setup Your own gadget and data have assurance as you bank, shop and post on the web, both at home and on open Wi-Fi.

Mark William said...

Kaspersky is an antivirus software designed in kaspersky download. It offers real-time protection, removal, and detection of viruses and malwares. On creating the kaspersky login account, you can download kaspersky antivirus on your device. The Kaspersky was basically designed to protect the device from malwares. The automatic backup, online identity protection, and costless technical support is available for kaspersky.com/downloads users. However, to cover all the devices with protection shield, www.kaspersky.com/downloads is essential. It is compatible with windows, mac, and mobile phones, including iOS and Android.

Zoe said...

Thanks for posting such a valuable information
best christmas gifts for mom
best gifts for dad 2020
best baby gifts 2020

nortonhelpline said...

I really happy found this website eventually. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog.

norton.com/setup

Charter.net

www.norton.com/setup

roadrunner email login

primevideo.com/mytv said...

norton.com/setup www.norton.com/setup my.norton.com The modern world is extremely different from what it used to be just a few years ago and it continues to change and evolve every other day. With the advent of technology, our routine lives as well as professional and academic routines have become so much easier and convenient. From tools that help you accomplish complex tasks to the wonderful world of social media that lets you share everything with your friends and family. But while technology has brought a lot of good into our lives, it has also exposed us to a lot of danger.

Computer Security said...

I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable.how to download bitdefender already paid for

Computer Security said...

Thanks for sharing this valuable content with us this work is appreciable.
www.malwarebytes.com/install

Computer Security said...

Thank for your writting. You have made it very clear that the problem is happening. I really like your way of thinking. www.webroot.com/safe

Computer Security said...

Thank you for your article that is useful for me, and I will save the name of your blog, I will definitely return to read your new article. webroot.com/safe

Computer Security said...

Excellent and nice post. It will beneficial for everyone. Thanks for sharing such a wonderful post. To read more visit our post which link has been given below.visit: www.avg.com/retail

Computer Security said...

I really like your post, I always like to read a quality content having accurate information regarding the subject. Thanks for sharing. It is such a very amazing post...www.avg.com/activation

Computer Security said...

Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. You may check our website also. www.malwarebytes.com/install

Computer Security said...

Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. malwarebytes downloads for already purchased

Victoria's Secret Gift Card said...

Thanks for the great comment buddy! You inspired me too by these beautiful words. Keep blogging on and achieve your goals. No one can stop you if you have guts to do something.
All The Best!
Thankyou
https://www.victoriasecretgiftcardbalance.com/check/
Victoria Secret Gift Card Balance
Victoria Secret Card Balance
Check Victoria's Secret Gift Card Balance
Victoria Secret Check Balance
Victoria Secret Gift Card Amount
Check Victoria's Secret Card Balance
Check My Victoria Secret Gift Card Balance
Victoria's Secret Gift Card
Victoria's Secret Gift Card Balance
Victoria Secret Gift Card
Victoria Secret Check Gift Card Balance

Target Visa Gift Card Balance Check said...

Thank you for your article that is useful for me, and I will save the name of your blog, I will definitely return to read your new article.

target visa gift card balance
target visa balance
target visa card balance
check target visa gift card balance
target visa prepaid card balance
mybalancenow target
check mybalancenow
target prepaid visa balance
visa prepaid card balance target
target visa check balance
visa target gift card balance
target visa debit gift card balance
check my target visa gift card balance
target balance check
check balance on target visa gift card
target visa prepaid card
target prepaid card visa
target visa gift card balance check
target visa gift card check balance

OneVanilla Balance Check said...

Thanks for sharing this information...

onevanilla gift card
onevanilla check balance
onevanilla balance check
onevanilla balance
onevanilla card balance
onevanilla prepaid visa card balance
www onevanilla balance
check my vanilla visa balance
onevanilla prepaid visa card
vanilla balance
onevanilla balance
one vanilla balance
check onevanilla balance
check vanilla balance
check one vanilla balance
onevanilla gift balance
onevanilla master card balance
onevanilla balance ceck
onevanilla balance check online
onevanilla online balance check
onevanilla balance visa
onevanilla visa balance
onevanilla prepaid balance
onevanilla mastercard balance
onevanilla card balance check
onevanilla prepaid balance check

Movies2Club.com said...

This is very interesting, You are an excessively professional blogger.
I have joined your feed and sit up for seeking extra of your great post.
Also, I've shared your site in my social networks

tamil new movie download
new movie download
new hindi movie download
new tamil movie download
new south movie download
new bollywood movie download
tamil new movie free download
new hd movie download
new hollywood movie download
new south movie hindi dubbed download
south movie download
south movie hindi dubbed download
south hindi dubbed movie download
south hindi dubbed sky movie download
new south movie 2019 hindi dubbed download
hollywood movie download
hollywood movie in hindi download
hollywood movie download in hindi
hollywood movie hindi dubbed download

Check Sephora Gift Card Balance said...

Thanks for taking the time to share with us such a great article. I found such a significant number of fascinating stuff with regards to your blog particularly its discussion. Keep doing awesome.
https://www.sephoragiftcardbalance.com/
Sephora Gift Card Balance Sephora Gift Card Balance Check Sephora Card Balance Sephora Check Balance Jcpenney Sephora Gift Card Balance Check Sephora Gift Card Balance Sephora Check Gift Card Balance Sephora Gift Card Check Balance Check Gift Card Balance Sephora Sephora Gift Card Balance Sephora Gift Card Balance Check Sephora Card Balance Sephora Check Balance Jcpenney Sephora Gift Card Balance Check Sephora Gift Card Balance Sephora Check Gift Card Balance Sephora Gift Card Check Balance Check Gift Card Balance Sephora

Nordstrom Gift Card Balance Check said...

Thanks for publishing this details. I simply wish to let you know that I just looked into your site and also I found it really fascinating and useful.
https://www.nordstormgiftcardbalance.com/
Nordstrom Gift Card Balance Check Nordstrom Gift Card Balance Nordstrom Card Balance Nordstrom Rack Gift Card Balance Nordstrom Gift Balance Nordstrom Rack Gift Card Balance Nordstrom Gift Balance Nordstrom Check Gift Card Balance Nordstrom Gift Card Balance Check Nordstrom Gift Card Balance Information Nordstrom Gift Card Nordstrom Gift Card Check Nordstrom Gift Card Check Balance Nordstrom Gift Card Balance Check Nordstrom Gift Card Balance Nordstrom Card Balance Nordstrom Rack Gift Card Balance Nordstrom Gift Balance Nordstrom Rack Gift Card Balance Nordstrom Gift Balance Nordstrom Check Gift Card Balance Nordstrom Gift Card Balance Check Nordstrom Gift Card Balance Information Nordstrom Gift Card Nordstrom Gift Card Check Nordstrom Gift Card Check Balance

Onevanilla Visa Balance said...

Thanks for the great comment buddy! You inspired me too by these beautiful words. Keep blogging on and achieve your goals. No one can stop you if you have guts to do something.
All The Best!
Thankyou
https://www.icedvanillalatte.com/check-onevanilla-gift-card-balance/
Onevanilla Card
Onevanilla Prepaid Visa Card Onevanilla Prepaid Card Onevanilla Balance Onevanilla Check Balance Onevanilla Card Balance Onevanilla Gift Card Balance Onevanilla Visa Card Onevanilla Prepaid Visa Card Balance Onevanilla Prepaid Card Balance Onevanilla Visa Balance OneVanilla Prepaid Mastercard Balance Onevanilla Prepaid Balance Check Onevanilla Card Balance One Vanilla Mastercard Balance Onevanilla Card Onevanilla Prepaid Visa Card Onevanilla Prepaid Card Onevanilla Balance Onevanilla Check Balance Onevanilla Card Balance Onevanilla Gift Card Balance Onevanilla Visa Card Onevanilla Prepaid Visa Card Balance Onevanilla Prepaid Card Balance Onevanilla Visa Balance OneVanilla Prepaid Mastercard Balance Onevanilla Prepaid Balance

soliha said...

kaspersky activation process online help and support regarding your product
stay safe and secure by activating your kaspersky antivirus

soliha said...

kaspersky activation process online help and support regarding your product
stay safe and secure by activating your kaspersky antivirus

soliha said...

kaspersky activation process online help and support regarding your product
stay safe and secure by activating your kaspersky antivirus

soliha said...

kaspersky activation process online help and support regarding your product
stay safe and secure by activating your kaspersky antivirus

soliha said...

kaspersky activation process online help and support regarding your product
stay safe and secure by activating your kaspersky antivirus

soliha said...

kaspersky activation process online help and support regarding your product
stay safe and secure by activating your kaspersky antivirus

Target Visa Gift Card Balance Check said...

Great. It is very useful information. Thanks for giving us this meaningful and helpful information...

target visa gift card balance,
target visa balance,
target visa card balance,
check target visa gift card balance,
target visa prepaid card balance,
mybalancenow target,
check mybalancenow,
target prepaid visa balance,
visa prepaid card balance target,
target visa check balance,
visa target gift card balance,
target visa debit gift card balance,
check my target visa gift card balance,
target balance check,
check balance on target visa gift card,
target visa prepaid card,
target prepaid card visa,
target visa gift card balance check,
target visa gift card check balance,

soliha said...

kaspersky activation process online help and support regarding your product
stay safe and secure by activating your kaspersky antivirus

soliha said...

kaspersky activation process online help and support regarding your product
stay safe and secure by activating your kaspersky antivirus

soliha said...

kaspersky activation process online help and support regarding your product
stay safe and secure by activating your kaspersky antivirus

soliha said...

kaspersky activation process online help and support regarding your product
stay safe and secure by activating your kaspersky antivirus

soliha said...

kaspersky activation process online help and support regarding your product
stay safe and secure by activating your kaspersky antivirus

tohulu said...

I think I have never seen such blogs ever before that has complete things with all details which I want. So kindly update this ever for us.
www.primevideos.com/mytv
www.prime.com/mytv
www.primevideos.com/mytv
www.hulu.com/activate
www.primevideos.com/mytv

Anonymous said...

Hey guys, anybody wanna buy some antivirus software? Ten dollars!

Shit, I forgot the link.

Computer Security said...

I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. Thanks for sharing the information keep updating, looking forward to more post.www.trendmicro.com/downloadme

Computer Security said...

Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.www.webroot.com/safe

Computer Security said...

www.norton.com/setup :The digital world is mediated through the internet, and it is the main source of different information shared on the internet.

shalin parker said...

Amazon Prime is a first class Television Based App feature giving a great deal of on-request and live films and TV shows, particularly with no ads. Amazon Prime gives clients moment admittance to a few sorts of current shows from all the large communicating networks in the U.S. The enrollment gives supporters boundless motion pictures, current just as past mainstream TV shows. Amazon Prime is a comprehensive amusement channel on Amazon Prime Tv.

www.primevideo.com/mytv
www.primevideo/mytv
www.primevideo.com/mytv register code

ronald said...

Interface your gadget to the Internet and go to the App Store.
Search and "Download" the Amazon prime video application.
When the document is downloaded and introduced, open the application.
You will see an alternative – "Register on Amazon site", click on this.
A 6 digit code will show up on the screen.
Note down this code cautiously. This is amazon.com/mytv enter code.
Presently open the Amazon site – Amazon.com/mytv.com and sign in with account subtleties.
Presently enter the Amazon enactment code and snap on "Proceed".
You will get the compliment message on your TV screen after the effective enactment.
Start Enjoying the amazon prime videos on your device.
If you are facing some issue in that process then you can visit :
primevideo.com/mytv
www.amazon.com/mytv registration
www.primevideo.com/mytv
www.amazon.com/mytv enter code

Nancy Angel said...

Best method to create your primevideo mytv code account through the activation process by primevideo.com/mytv. You need to follow the instructions to activate www.amazon.com. If you are viewing Amazon Prime Video on your device go toamazon enter code.

primevideocommytv said...

Initiation of amazon Prime should be possible from either interface Amazon.com/mytv or Primevideo.com/mytv. Both link give admittance to amazon prime sign-in and activation. The user ought to have 6 Digit Activation codes before login into this connection. Amazon prime membership can begin after you log in to these links.
Read more…

peter hawks said...

Explainer Video Company New York
===========================
Explainer videos Services new york | Explainer videos Company
Explainer videos company are short online marketing videos used to illustrate the product or service of your business. These videos are often placed on a landing page, your website home page, or a prominent product page.

peter hawks said...

/My Amazon prime video TV Help
=============================
www.amazon.com/mytv - Enter Mytv Code - PrimeVideo.com
visit Amazon MYTV Enter code or www.primevideo.com/mytv and enter Amazon activation code to activate amazon prime videos on your smart tv and pc

peter hawks said...

Sling TV Pack Activation Help
======================
www.Sling.com/Activate | Activate Sling Tv | Sling.com/Activate
www.Sling.com/Activate Roku Steps, Sling TV Packages and Sling TV offers you an amazing alternative for cable at a cheap price. You can avail of many live channels including local channels with the Sling TV package subscription. Sling TV is supported on many devices including Roku.

peter hawks said...

Amazon My TV Help
=========================
www.amazon.com/mytv - Enter Mytv Code - PrimeVideo.com
visit www.amazon.com/mytv or www.primevideo.com/mytv and enter Amazon activation code to activate amazon prime videos on your smart tv and pc

primevideo.com/mytv code said...


Copy and paste the web link link in your web browser that is www.amazon.com/mytv. Login to your prime video account using your prime video login credentials. After that enter the activation code you have on your screen .Devices Compatible with Prime Video. Exclusive content and Amazon Original series Enjoy exclusive movies and TV shows on your device.

Unknown said...

YouTube is just one of those available stations on many Roku apparatus, also you may sign in with your YouTube accounts to view most your programs and play lists. You might even apply your smartphone, tabletcomputer, or computer to get and play with YouTube videos onto your own Roku rather than employing the Roku remote.
youtube.com/activate
www.youtube.com/activate

Unknown said...

Tubi's complimentary streaming agency is a pleasing surprise, even with a vast assortment of quirky and classic pictures and television collection. It's ad-supported, nevertheless, you'll run in to more adverts on freetoair than simply while seeing among Tubi's b movies.
tubi.tv/activate
tubi.tv/activate enter code
tubi.tv/activate

Daniel Coper said...

Thanks For Sharing Such An Amazing Post Enjoyed Reading it.

Regards

www.primevideo.com/mytv
www.primevideo/mytv
www.primevideo.com/mytv
www.amazon.com/mytv
amazon.com/mytv
amazon.com/mytv
www.netflix.com/activate