I think Racket handles this pretty well. The rule it defines is that a module 
cannot directly mutate another module's top-level symbols. This means that if a 
module itself does not contain any mutations of a top-level function, that 
definition cannot be changed at runtime. Therefore, everyone can rely on a 
simpler calling convention that doesn't require the extra level of indirection 
needed to handle changeable top-level symbols.

However, if the module contains a 'set!' or equivalent to a top-level symbol, 
then references to that symbol will have to be loaded each time, since it is 
possible for the value to change.

e.g.

#lang racket

(define (f1)
  (println "f1"))

(define (f2)
  (println "f2"))

;; The existence of the "set!" in this function means that 'f1' cannot be 
directly called, within or without this module.
(define (alter)
  (set! f1 f2))

(module+ main
  (f1)
  ; (set! f1 f2)   ;; Not allowed
  (alter)     ;; Allowed
  (f2))

On 8/14/18, 7:51 AM, "Arthur Nunes-Harwitt" <racket-users@googlegroups.com on 
behalf of a...@cs.rit.edu> wrote:

    Hi,
    
       Racket seems to depricate redefinition of functions at run-time.  Since 
    Racket isn't Scheme, why not prevent that and get back that performance?
    
    -Arthur
    
    ==============================================================
    Arthur Nunes-Harwitt
    Computer Science Department, Rochester Institute of Technology
    Room 70-3509
    585-475-4916
    ==============================================================
    
    "I don't know what the language of the future will be
    called, but it will look like LISP."
    
    This email is confidential and intended for the named recipient(s). In
    the event the email is received by someone other than the recipient,
    please notify the sender at a...@cs.rit.edu.
    
    On Mon, 13 Aug 2018, George Neuner wrote:
    
    >
    > On 8/13/2018 10:02 AM, 'Paulo Matos' via Racket Users wrote
    >> On 11/08/18 19:41, Sam Tobin-Hochstadt wrote:
    >> > There are basically two differences between the `unsafe-lsb` function
    >> > in Racket and the C one:
    >> >  - the Racket calling convention vs the C calling convention
    >> >  - the instruction used to perform the LSB calculation
    >> > > For a variety of reasons Racket's function calling convention is more
    >> > heavyweight than C's, but if that code is inlined into some larger
    >> > function that will go away (as it would in C). The simpler instruction
    >> > used by the C compiler is because the C compiler recognizes that
    >> > pattern of bitwise and, whereas the Racket JIT does the obvious `and`.
    >> > That could of course be fixed in the JIT, although it's not clear how
    >> > much of a win it is. 
    >> Is this something that will change with Racket-on-Chez? i.e. Racket will
    >> then use the Chez optimizer to generate machine code?
    >
    > Racket's function call convention is heavier than C's because it has to 
deal 
    > with the possibility that functions may be redefined at runtime, or may 
be 
    > overloaded ... things C does not have to deal with.  The same function 
may 
    > have multiple entry points depending on number of arguments, or presence 
of 
    > keywords, etc.  And functions that may be redefined must be called 
indirectly 
    > to avoid (re)patching every call site when/if the definition changes.  
These 
    > things make (average) function calling in Racket slower than in C.
    >
    > It is expected that the Chez compiler will do a better job at optimizing 
    > code, but it can't overcome differences in call semantics.  If you do 
    > something "schemely" with your functions, then you WILL pay the price for 
it.
    >
    > George
    >
    > -- 
    > You received this message because you are subscribed to the Google Groups 
    > "Racket Users" group.
    > To unsubscribe from this group and stop receiving emails from it, send an 
    > email to racket-users+unsubscr...@googlegroups.com.
    > For more options, visit https://groups.google.com/d/optout.
    >
    
    -- 
    You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an 
email to racket-users+unsubscr...@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to