Supressed Printing.



; The Instprog library is growing - now it defines 146 functions  
; and 87 macros, although many of these are duplicated, for example,
; set-undefined and SU do same thing, much like USA and united-states-...
; I admit, most of these are more, well, "conceptual" than practical.
;
; In recent versions, all functions and macros in the library are
; protected with my function protect1 already described in this
; blog. Although I do not use contexts, the naming conventions
; should ensure that functions and macros are equally "safe".
;
; Also, the library is pretty verbose. It performs about 60 tests
; and report results. In recent versions I redefined functions
; print and println so these reports can be turned off.

(set 'print.supressed true
     'println.supressed true)
     
(load "http://www.instprog.com/Instprog.default-library.lsp")

(set 'print.supressed nil
     'println.supressed nil)
     
(exit)

; Redefinitions of print and println are in the library, so after
; library is loaded, any printing can be supressed on the same way.

(set 'print.original print 'println.original println)
(set 'lambda-last (lambda()(last(args))))

(constant 'print
          (lambda-macro()(eval (cons (if print.supressed
                                         lambda-last
                                         print.original)
                                         (args)))))

(constant 'println (lambda-macro()(eval (cons (if println.supressed
                                                  lambda-last
                                                  println.original)
                                             (args)))))
                                             

; Redefined print can be combined with "device" expression.

Note: in new version, one should use [print.supressed] and [println.supressed] instead of print.supressed and println.supressed.


--

3 comments:

  1. Hi, Kazimir, this is "unixtechie" from the newlisp forum.

    I really enjoy your posts, so I recently looked at your sites again - and realized you are "on a mission" to study and create a library or a catalogue of useful higher-order programming techniques.

    That reminded me of something that might come useful (and something I myself wanted to do some time ago, actually).
    There's a book, which can be viewed as an expostulation of results of several years of thinking on programming paradigms and programming primitives, the most basic ones, that those paradigms are built from. Or this book can be viewed as a course in Computer Science, whatever your preference is.

    The approach by the authors is this: let's take a minimal number of the most simple functionalities (such as assignement) and see what is necessary to build "pure functional programming" . Let's then add something to it, such as a concept of "laziness" or "state" etc. - and see how this expands into another paradigm.

    The book is "Concepts, TEchniques and Models of Computer Programming" by Peter Van Roy and Seif Haridi - and a draft from 2003 (published by MIT in 2004) is available on the Net.
    The official web site is http://www.info.ucl.ac.be/~pvr/book.html - and I've got a PDF, but do not remember where I got it from.

    The book is written using Mozart-Oz programming language, but it is independent from the language itself - examples in the text can be treated as simply "pseudocode", as the main usefullness of the work lies in their "core language" approach, the reduction of programming to a set of basics.

    My idea was to translate - or express - the primitives in NewLisp.
    This would be not only interesting as a mental exercise, but very, very practical too. And possibly with academic value, as an application of the general approach to practical programming in a Lisp type of language.

    A web search gives the URL of the PDF right from the book official site:
    www.info.ucl.ac.be/~pvr/Concepts.pdf

    Check it

    ReplyDelete
  2. Sorry, the book URL was wrong - that pdf was a 20-page presentation.
    The book is at
    http://www.librecours.org/documents/5/521.pdf

    ReplyDelete
  3. Hi, unixtechie

    thank you on recommendation, it is great and large book. I have two projects in following 2-3 years, one is writing of one automated theorem proving tool, another is research of metaprogramming in Newlisp, by metaprogramming I think on things like eval or that crawler tractor etc. So, it is more narrow than Concept, Techniques and Models ... but I agree with you, it is great idea and book and it would be great if someone does that, even in less extensive version of some 200-300 pages.

    ReplyDelete