Ad blocker interference detected!
Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers
Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.
This page tries to estimate the amount of work required to port Sawfish from rep/rep-gtk to Racket. There is nothing official about it, and it can also be useful for anyone interested in porting Sawfish to another language, like Chicken.
(So this page is not to discuss the benefits of Racket for Sawfish, but only to consider what should be done to port it.)
Note: A project has been started here. It is not a direct port of Sawfish, but a rewrite from scratch. Its aim is to be very similar to Sawfish (extensibility, scripting in Scheme, console, etc.), but there may be differences.
- Rep manual (latest version?)
- Sawfish programming manual (bit outdated, any better version somewhere?)
- Racket reference manual
- Racket guide for newbies
- http://listengine.tuxfamily.org/lists.tuxfamily.org/sawfish/2012/06/msg00013.html (and subsequent emails in the thread)
- https://mail.gnome.org/archives/sawfish-list/2011-April/msg00025.html (porting to Guile)
In variable binding, namespaces, module loading, etc.
- Modules and features
- Exceptions and continuations
- Threads (shouldn't be too problematic)
- Rep: dynamic scoping, used like normal variables
- Racket: parameters, used like fluid-variables (?) with a bit less "dynamic scope" (for safety reasons). Like Rep, Racket can define global variables with 'define', which are used (almost) like if defined with a global surrounding 'let'.
- Rep: unbounded variable
- Racket: unbounded = #<undefined>, 'void' is a function that consumes all its arguments and returns #<void>, which serves as the output of functions that return no value
- Rep: mutable cons cells
- Racket: immutable cons cells by default (mutable cells exist too)
- Rep: 'nil' or '() is false, any other value is like true, 't'.
- Racket: false is 'false' or #f, any other value (including '()) is like true ('true', #t). 'nil' does not exist, and is 'null', which is '().
- Rep: (if test expr-true expr-false ...)
- Racket: (if test expr-true expr-false)
- Rep: seems "transparent" for define (and the rest of the top level?) ( http://librep.sourceforge.net/librep-manual.html#Scope%20and%20Extent )
- Racket: in the above example, 'count' would not be accessible from outside the let
- Rep: lisp-like, using defmacro
- Racket: hygienic macros (define-syntax)
- Eli Barzilay says it should be fairly easy to port them and may help with it
- Racket also has a legacy defmacro wich may be useful in a first step, but hygienic macros are much safer and less error-prone, especially for 3rd-party scripts. Most simple macros are very easy to write in the hygienic system too. For example, the 'when' macro could be (re)defined by:
(define-syntax-rule (when test body ...) (cond (test body ...)))
- Rep: in define, defun, lambda, defvar, etc.
- Racket: does not have doc-strings by default, but it should be easy to add support for them when defining the Racket/Sawfish interface
- Racket: Nothing that I know of, but should be easy to implement
Mainly bindings to Xlib through the FFI (?), or maybe better to XCB (though that would probably require additional work).
There is already a Xlib bindings package for Racket.
Racket already uses GTK for its GUI.
Simple rewritings and conventionsEdit
- Rep: predicates end in '-p' or 'p'.
- Racket: predicates end in '?'
- Rep: define, defun with doc-string
- Racket: define (without doc-strings, but should not be difficult to add)
- Fluid variables
- Rep: make-fluid, let-fluid
- Racket: make-parameter, parameterize
- Rep: 
- Racket: vector ( is like () in Racket)
- setq --> set! ('!' means mutation)
- set --> nothing yet, would require a macro if needed (I think)
- prog1, progn --> begin0, begin
- Keywords arguments
- Rep: ':the-keyword'
- Racket: '#:the-keyword'
- Special arguments
- (lambda (#!optional a (b 5)) ...) --> (lambda ((a #f) (b 5)) ...)
- !rest --> .
- !key: ((lambda (a #!key b c) (list a b c)) 1 #:b 2 3) --> ((lambda (a #:b b #:c c) (list a b c)) 1 #:b 2 3)
- In Racket, keyword arguments cannot be used as non-key arguments
- 1+, 1- --> add1, sub1
- mapcar --> map
- mapc --> for-each (but returns #<void> instead of the last value)
How to port Sawfish to RacketEdit
It may be simpler in a first step to write a compatibility interface in Racket to make sure that Sawfish runs over Racket, and in a second step slowly change Sawfish code to Racket's philosophy. This would also ensure that nothing/little breaks in 3rd party scripts.
Note: It would probably be safer to initially make no binding visible to Sawfish-racket, so that every rep binding has to be defined explicitly or raise an error if not defined (i.e., don't fall in the simplicity solution to not redefine the binding that seem to have the same meaning in rep and Racket).
Other possibilities: Do not try to make a Rep substitute but use the opportunity to adapt to Racket's way? For some issues it may require less work, but maybe not for most.
It would be useful to know what part of Rep does not need to be ported to Racket (e.g., are remote files needed?)
Foreign Function InterfaceEdit
Racket provides a good foreign function interface (FFI) which should make it easy to bind the current sawfish/rep C code, although the project should become entirely independent of rep.