This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Simple Printing/formatting a list in Scheme

2 posts · 4171 views

Hi everyone,

I just want to print out a list (containing a string and a number) in this format:

Orange : 3

With my code, I'm getting the following error:

Orange : (3). . application: not a procedure;
expected a procedure that can be applied to arguments
given: #<void>
arguments...:

Would appreciate the guidance.

Thanks!
#lang scheme

(define t '( "Orange" 3))


(define print-object (lambda (m)
                     (
                      (display (name m))
                      (display " : ")
                      (display (priority m))
                      )))

(print-object t)

Re: Simple Printing/formatting a list in Scheme

Hi,

In Scheme, the first expression in a list is treated as a function to be evaluated.
You have an extra set of parentheses in the lambda form.
This is causing the undesired evaluation.

In languages like C/C++/Java, an extra level of {}s does nothing.
In the Lisp family of languages, an extra level of ()s usually causes evaluation.

Try the following code.
(define print-object
  (lambda (m)
    (display (car m))
    (display " : ")
    (display (cadr m))))
(print-object '("Orange" 3))