From: Francogrex
Subject: Histogram in lisp?
Date: 
Message-ID: <45a908f0-ee91-4fcc-b808-a8b8f92d405e@x8g2000yqk.googlegroups.com>
Hi  question about a code for drawing a histogram:

(setf count (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76 78 49
18 8 36 15))

(setf br (list 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
1967 1968 1969 1970
	       1971 1972 1973 1974 1975 1976 1977 1978 1979))

(setf str2 (open "C:/histo.txt" :direction :output))
(dotimes (i (length count))
  (format str2 "~A ~A~%" (loop repeat  (nth i count) do (format str2
"*")) (nth i br)))
(close str2)

[content of histo.txt"]

**********NIL 1956
NIL 1957
***********NIL 1958
*******NIL 1959
************NIL 1960
***********NIL 1961
**************************************************************NIL 1962
***********************NIL 1963
etc...

But I don't want that it prints NIL. How can I write the code so that
the output is more like this:
1956 **********
1957
1958 ***********
etc...

From: Jeff M.
Subject: Re: Histogram in lisp?
Date: 
Message-ID: <898345b2-47ad-4e2a-a9a6-1c1a0ee443ce@o2g2000yqd.googlegroups.com>
On Dec 1, 1:25 pm, Francogrex <······@grex.org> wrote:
> Hi  question about a code for drawing a histogram:
>
> (setf count (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76 78 49
> 18 8 36 15))
>
> (setf br (list 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
> 1967 1968 1969 1970
>                1971 1972 1973 1974 1975 1976 1977 1978 1979))
>
> (setf str2 (open "C:/histo.txt" :direction :output))
> (dotimes (i (length count))
>   (format str2 "~A ~A~%" (loop repeat  (nth i count) do (format str2
> "*")) (nth i br)))
> (close str2)
>
> [content of histo.txt"]
>
> **********NIL 1956
> NIL 1957
> ***********NIL 1958
> *******NIL 1959
> ************NIL 1960
> ***********NIL 1961
> **************************************************************NIL 1962
> ***********************NIL 1963
> etc...
>
> But I don't want that it prints NIL. How can I write the code so that
> the output is more like this:
> 1956 **********
> 1957
> 1958 ***********
> etc...

Just a few tips that might help you simplify the code some:

* Take a look at VECTOR and ELT or AREF instead of NTH
* Take a look at DOLIST instead of DOTIMES
* Take a look at WITH-OPEN-FILE

As for your problem with NIL, here's a hint:

http://www.lispworks.com/documentation/HyperSpec/Body/f_format.htm#format

What does FORMAT return?

HTH,
Jeff M.
From: Thomas A. Russ
Subject: Re: Histogram in lisp?
Date: 
Message-ID: <ymik5ajhaay.fsf@blackcat.isi.edu>
Francogrex <······@grex.org> writes:

> Hi  question about a code for drawing a histogram:
> 
> (setf count (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76 78 49
> 18 8 36 15))
> 
> (setf br (list 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
> 1967 1968 1969 1970
> 	       1971 1972 1973 1974 1975 1976 1977 1978 1979))
> 
> (setf str2 (open "C:/histo.txt" :direction :output))
> (dotimes (i (length count))
>   (format str2 "~A ~A~%" (loop repeat  (nth i count) do (format str2
> "*")) (nth i br)))
> (close str2)
> 
> [content of histo.txt"]
> 
> **********NIL 1956
> NIL 1957
> ***********NIL 1958
> *******NIL 1959
> ************NIL 1960
> ***********NIL 1961
> **************************************************************NIL 1962
> ***********************NIL 1963
> etc...
> 
> But I don't want that it prints NIL.

Well, first of all, do you understand why it prints NIL?

> How can I write the code so that
> the output is more like this:
> 1956 **********
> 1957
> 1958 ***********
> etc...

For doing what you want, I would first of all use a completely different
data structure.  I'm not a fan of having separate lists that have to be
kept in sync with each other as a means of having a what is really a
two-dimensional structure.

For your case, I would use a simple alist (association list) to hold the
data.  I would also arrange it so that the key to the list is the year,
rather than the count.  That also provides a nice, easy and reasonably
efficient (for small data sets) method for creating the data in the
first place.  [Doing that is left as an exercise for the reader.]

I would also use a convenience macro WITH-OPEN-FILE, to handle the
writing with propery unwind-protection to close the stream.

Finally, I would make the iteration be much, much more efficient.  As a
general hint, you * never want to use NTH to iterate over a list.

(defvar *data* 
        '((1956 . 10) (1957 . 0) (1958 . 11) (1959 . 7)
	  (1960 . 12) (1961 . 11) (1962 . 62) (1963 . 23) (1964 . 28)
	  (1965 . 29) (1966 . 46) (1967 . 70) (1968 . 16) (1969 . 37)
	  (1970 . 8) (1971 . 3) (1972 . 76) (1973 . 78) (1974 . 49)
	  (1975 . 18) (1976 . 8) (1977 . 36) (1978 . 15)))

(with-open-file (stream "C:/histo.txt" :direction :output)
  (loop for (key . count) in *data*
        do (format stream "~4D ~v,,,'*A~%" key count "")))

I used LOOP, mainly to get the nice, convenient destructuring of the
data values.  It would be possible to use DOLIST instead, at the cost of
having to extract the data item values explicitly:

  (dolist (item *data*)
    (format stream "~4D ~v,,,'*A~%" (car item) (cdr item) ""))

Incidentally, I quickly produced the ALIST for *data* by using your
initial code and executing (mapcar #'cons br count) on it.

* almost, except in some really, really specialized circumstances,
  perhaps.  But they don't apply here.
-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: D Herring
Subject: Re: Histogram in lisp?
Date: 
Message-ID: <gh239i$lh1$1@aioe.org>
Francogrex wrote:
> Hi  question about a code for drawing a histogram:
...

FWIW,
http://www-2.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/math/hist/0.html

The only tweaks needed to get this running in SBCL 1.0.22 was
- (in-package "HIST")
+ (defpackage :hist
+   (:use :cl))
+ (in-package :hist)

Then

CL-USER> (hist:hist (0 10 2) (dotimes (i 100) (hist:hist-record 
(random 10))))
< 0:        0
0:          22      ######################
2:          24      ########################
4:          18      ##################
6:          15      ###############
8:          21      #####################
 > 10:       0
NIL

- Daniel
From: Rainer Joswig
Subject: Re: Histogram in lisp?
Date: 
Message-ID: <joswig-DA9CA8.21465301122008@news-europe.giganews.com>
In article 
<····································@x8g2000yqk.googlegroups.com>,
 Francogrex <······@grex.org> wrote:

> Hi  question about a code for drawing a histogram:
> 
> (setf count (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76 78 49
> 18 8 36 15))
> 
> (setf br (list 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
> 1967 1968 1969 1970
> 	       1971 1972 1973 1974 1975 1976 1977 1978 1979))
> 
> (setf str2 (open "C:/histo.txt" :direction :output))
> (dotimes (i (length count))
>   (format str2 "~A ~A~%" (loop repeat  (nth i count) do (format str2
> "*")) (nth i br)))
> (close str2)
> 
> [content of histo.txt"]
> 
> **********NIL 1956
> NIL 1957
> ***********NIL 1958
> *******NIL 1959
> ************NIL 1960
> ***********NIL 1961
> **************************************************************NIL 1962
> ***********************NIL 1963
> etc...
> 
> But I don't want that it prints NIL. How can I write the code so that
> the output is more like this:
> 1956 **********
> 1957
> 1958 ***********
> etc...

? (let ((c (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76 78 49 18 8 36 15))
        (b (list 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 
                 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979)))
    (loop for c1 in c and b1 in b
      do (print b1) (princ " ") (loop repeat c1 do (write-char #\*))))

1956  **********
1957  
1958  ***********
1959  *******
1960  ************
1961  ***********
1962  **************************************************************
1963  ***********************
1964  ****************************
1965  *****************************
1966  **********************************************
1967  **********************************************************************
1968  ****************
1969  *************************************
1970  ********
1971  ***
1972  ****************************************************************************
1973  ******************************************************************************
1974  *************************************************
1975  ******************
1976  ********
1977  ************************************
1978  ***************

-- 
http://lispm.dyndns.org/
From: William James
Subject: Re: Histogram in lisp?
Date: 
Message-ID: <7e98bf6a-98eb-4258-8cf7-f140233cc1f3@v42g2000yqv.googlegroups.com>
On Dec 1, 2:46 pm, Rainer Joswig <······@lisp.de> wrote:
> In article
> <····································@x8g2000yqk.googlegroups.com>,
>
>
>
>  Francogrex <······@grex.org> wrote:
> > Hi  question about a code for drawing a histogram:
>
> > (setf count (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76 78 49
> > 18 8 36 15))
>
> > (setf br (list 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
> > 1967 1968 1969 1970
> >           1971 1972 1973 1974 1975 1976 1977 1978 1979))
>
> > (setf str2 (open "C:/histo.txt" :direction :output))
> > (dotimes (i (length count))
> >   (format str2 "~A ~A~%" (loop repeat  (nth i count) do (format str2
> > "*")) (nth i br)))
> > (close str2)
>
> > [content of histo.txt"]
>
> > **********NIL 1956
> > NIL 1957
> > ***********NIL 1958
> > *******NIL 1959
> > ************NIL 1960
> > ***********NIL 1961
> > **************************************************************NIL 1962
> > ***********************NIL 1963
> > etc...
>
> > But I don't want that it prints NIL. How can I write the code so that
> > the output is more like this:
> > 1956 **********
> > 1957
> > 1958 ***********
> > etc...
>
> ? (let ((c (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76 78 49 18 8 36 15))
>         (b (list 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
>                  1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979)))
>     (loop for c1 in c and b1 in b
>       do (print b1) (princ " ") (loop repeat c1 do (write-char #\*))))

Nothing so bloated as "loop" is needed.  In fact, no looping is
needed.

Ruby:

c = %w( 10 0 11 7 12 11 62 23 28 29 46 70
        16 37 8 3 76 78 49 18 8 36 15).map{|s| s.to_i}
first_year = 1956
b = (first_year ... first_year + c.size)
puts b.zip(c).map{|yr,cnt| "#{yr} #{'*' * cnt}"}
From: Jeff M.
Subject: Re: Histogram in lisp?
Date: 
Message-ID: <5871e1ef-419b-4956-9567-ea8f92b5ff08@v42g2000yqv.googlegroups.com>
On Dec 1, 3:47 pm, William James <·········@yahoo.com> wrote:
> On Dec 1, 2:46 pm, Rainer Joswig <······@lisp.de> wrote:
>
> ... In fact, no looping is needed.
>
> c = %w( 10 0 11 7 12 11 62 23 28 29 46 70
>         16 37 8 3 76 78 49 18 8 36 15).map{|s| s.to_i}

What the hell do you think 'map' is? Magic?

Jeff M.
From: ··················@gmail.com
Subject: Re: Histogram in lisp?
Date: 
Message-ID: <9458bb89-f424-4958-a7c0-833c4257008e@f13g2000yqj.googlegroups.com>
> puts b.zip(c).map{|yr,cnt| "#{yr} #{'*' * cnt}"}

Yuck

I believe this is lisp homework,
so I don't think ruby will do any good...
From: Vsevolod
Subject: Re: Histogram in lisp?
Date: 
Message-ID: <624fda45-0126-4636-a80e-757d7b06db9f@v15g2000yqn.googlegroups.com>
> c = %w( 10 0 11 7 12 11 62 23 28 29 46 70
>         16 37 8 3 76 78 49 18 8 36 15).map{|s| s.to_i}
> first_year = 1956
> b = (first_year ... first_year + c.size)
> puts b.zip(c).map{|yr,cnt| "#{yr} #{'*' * cnt}"}

man, you should've written it in one line in best traditions of just
another Perl hacker (http://en.wikipedia.org/wiki/
Just_another_Perl_hacker)
From: ······@corporate-world.lisp.de
Subject: Re: Histogram in lisp?
Date: 
Message-ID: <27b707f8-f8c0-45c0-9c45-5d521bae2f7f@e18g2000yqo.googlegroups.com>
On 1 Dez., 22:47, William James <·········@yahoo.com> wrote:
> On Dec 1, 2:46 pm, Rainer Joswig <······@lisp.de> wrote:
>
>
>
> > In article
> > <····································@x8g2000yqk.googlegroups.com>,
>
> >  Francogrex <······@grex.org> wrote:
> > > Hi  question about a code for drawing a histogram:
>
> > > (setf count (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76 78 49
> > > 18 8 36 15))
>
> > > (setf br (list 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
> > > 1967 1968 1969 1970
> > >           1971 1972 1973 1974 1975 1976 1977 1978 1979))
>
> > > (setf str2 (open "C:/histo.txt" :direction :output))
> > > (dotimes (i (length count))
> > >   (format str2 "~A ~A~%" (loop repeat  (nth i count) do (format str2
> > > "*")) (nth i br)))
> > > (close str2)
>
> > > [content of histo.txt"]
>
> > > **********NIL 1956
> > > NIL 1957
> > > ***********NIL 1958
> > > *******NIL 1959
> > > ************NIL 1960
> > > ***********NIL 1961
> > > **************************************************************NIL 1962
> > > ***********************NIL 1963
> > > etc...
>
> > > But I don't want that it prints NIL. How can I write the code so that
> > > the output is more like this:
> > > 1956 **********
> > > 1957
> > > 1958 ***********
> > > etc...
>
> > ? (let ((c (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76 78 49 18 8 36 15))
> >         (b (list 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
> >                  1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979)))
> >     (loop for c1 in c and b1 in b
> >       do (print b1) (princ " ") (loop repeat c1 do (write-char #\*))))
>
> Nothing so bloated as "loop" is needed.  In fact, no looping is
> needed.
>
> Ruby:
>
> c = %w( 10 0 11 7 12 11 62 23 28 29 46 70
>         16 37 8 3 76 78 49 18 8 36 15).map{|s| s.to_i}

To create a vector of integers?


#(10 0 11 7 12 11 62 23 28 29 46 70 37 8 3 76 78 49 18 8 36 15)

> first_year = 1956
> b = (first_year ... first_year + c.size)
> puts b.zip(c).map{|yr,cnt| "#{yr} #{'*' * cnt}"}

you zip the to vectors to a new vector of vectors?
you map of the vectors to create strings?
Which then you have to iterate over again to print it?


That's a Ruby Goldberg Machine!  ( http://www.rubegoldberg.com/ )

Lisp looks nice.

? (histogram 1956 (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76
78 49 18 8 36 15))

1956  **********
1957

...

? (defun histogram (start list &aux (i (1- start)))
    (mapc (lambda (c) (print (incf i)) (princ " ") (loop repeat c do
(princ '*))) list))
HISTOGRAM


As a bonus it is interactively compiled to machine code...

? (disassemble 'histogram)
L0
  (leaq (@ (:^ L0) (% rip)) (% fn))
  (cmpw ($ 16) (% nargs))                         ;[7]
  (je.pt L17)                                     ;[12]
  (uuo-error-wrong-number-of-args)                ;[15]
L17
  (pushq (% rbp))
  (movq (% rsp) (% rbp))                          ;[18]
  (pushq (% arg_y))                               ;[21]
  (pushq (% arg_z))                               ;[22]
  (pushq (% save0))                               ;[23]
  (pushq (% save1))                               ;[25]
  (pushq (% save2))                               ;[27]
  (movq (@ -8 (% rbp)) (% arg_z))                 ;[29]
  (testb ($ 7) (% arg_z.b))                       ;[33]
  (jne L62)                                       ;[37]
  (addq ($ -8) (% arg_z))                         ;[39]
  (jno.pt L84)                                    ;[43]
  (callq (@ .SPFIX-OVERFLOW))                     ;[46]
  (leaq (@ (:^ L0) (% rip)) (% fn))               ;[53]
  (jmp L84)                                       ;[60]
L62
  (movq ($ -8) (% arg_y))
  (nop)                                           ;[69]
  (callq (@ .SPBUILTIN-PLUS))                     ;[70]
  (leaq (@ (:^ L0) (% rip)) (% fn))               ;[77]
L84
  (pushq (% arg_z))
  (movq (@ -48 (% rbp)) (% arg_z))                ;[85]
  (movl ($ 342) (% imm0.l))                       ;[89]
  (movl ($ 3) (% imm1.l))                         ;[95]
  (subq (% imm1) (@ (% gs) 216))                  ;[101]
  (movq (@ (% gs) 216) (% temp0))                 ;[110]
  (cmpq (@ (% gs) 224) (% temp0))                 ;[119]
  (jg L132)                                       ;[128]
  (uuo-alloc)                                     ;[130]
L132
  (movq (% imm0) (@ -13 (% temp0)))
  (andb ($ 240) (@ (% gs) 216))                   ;[136]
  (movq (% temp0) (% arg_y))                      ;[145]
  (movq (% arg_z) (@ -5 (% arg_y)))               ;[148]
  (movq (% arg_y) (@ -48 (% rbp)))                ;[152]
  (movq ($ 1941) (% imm0))                        ;[156]
  (movq ($ 51) (% imm1))                          ;[163]
  (subq (% imm1) (@ (% gs) 216))                  ;[170]
  (movq (@ (% gs) 216) (% temp0))                 ;[179]
  (cmpq (@ (% gs) 224) (% temp0))                 ;[188]
  (jg L201)                                       ;[197]
  (uuo-alloc)                                     ;[199]
L201
  (movq (% imm0) (@ -13 (% temp0)))
  (andb ($ 240) (@ (% gs) 216))                   ;[205]
  (movq (% temp0) (% arg_z))                      ;[214]
  (movq ($ 2666130979402886541) (% imm0))         ;[217]
  (movb ($ 4) (@ -5 (% arg_z)))                   ;[227]
  (movb ($ 76) (@ 2 (% arg_z)))                   ;[231]
  (movq (% imm0) (@ 3 (% arg_z)))                 ;[235]
  (movl ($ 5335077) (@ 11 (% arg_z)))             ;[239]
  (movb ($ 242) (@ 19 (% arg_z)))                 ;[246]
  (movq (@ '#<Anonymous Function #x300041C3536F> (% fn)) (% ra0)) ;
[250]
  (movq (@ -48 (% rbp)) (% arg_y))                ;[257]
  (movq (% ra0) (@ 27 (% arg_z)))                 ;[261]
  (movq (% arg_y) (@ 35 (% arg_z)))               ;[265]
  (movq ($ 4429185024) (% arg_y))                 ;[269]
  (movq (% arg_y) (@ 43 (% arg_z)))               ;[279]
  (addq ($ 2) (% arg_z))                          ;[283]
  (movq (% arg_z) (% save2))                      ;[287]
  (movq (@ -16 (% rbp)) (% save0))                ;[290]
  (movl ($ 12299) (% save1.l))                    ;[294]
  (jmp L356)                                      ;[301]
L303
  (movq (@ -3 (% save0)) (% save0))
  (movq (% save1) (% arg_z))                      ;[307]
  (movq (% save2) (% temp0))                      ;[310]
  (movw ($ 8) (% nargs))                          ;[313]
  (movb (% temp0.b) (% imm0.b))                   ;[318]
  (andb ($ 15) (% imm0.b))                        ;[320]
  (cmpb ($ 14) (% imm0.b))                        ;[323]
  (cmovgq (% temp0) (% temp1))                    ;[326]
  (jge.pt L335)                                   ;[330]
  (uuo-error-not-callable)                        ;[333]
L335
  (cmoveq (@ 10 (% temp0)) (% temp1))
  (nop)                                           ;[340]
  (nop)                                           ;[343]
  (callq (% temp1))                               ;[346]
  (leaq (@ (:^ L0) (% rip)) (% fn))               ;[349]
L356
  (movb (% save0.b) (% imm0.b))
  (andb ($ 7) (% imm0.b))                         ;[359]
  (cmpb ($ 3) (% imm0.b))                         ;[362]
  (je.pt L370)                                    ;[365]
  (uuo-error-reg-not-list (% save0))              ;[368]
L370
  (movq (@ 5 (% save0)) (% save1))
  (cmpb ($ 11) (% save0.b))                       ;[374]
  (jne L303)                                      ;[378]
  (movq (@ -16 (% rbp)) (% arg_z))                ;[380]
  (addq ($ 8) (% rsp))                            ;[384]
  (popq (% save2))                                ;[388]
  (popq (% save1))                                ;[390]
  (popq (% save0))                                ;[392]
  (leaveq)                                        ;[394]
  (retq)                                          ;[395]
From: Mirko
Subject: Re: Histogram in lisp?
Date: 
Message-ID: <e3e723ba-c368-4822-bcb7-245761403a80@t2g2000yqm.googlegroups.com>
On Dec 1, 6:40 pm, ·······@corporate-world.lisp.de" <······@corporate-
world.lisp.de> wrote:
> On 1 Dez., 22:47, William James <·········@yahoo.com> wrote:
>
>
>
> > On Dec 1, 2:46 pm, Rainer Joswig <······@lisp.de> wrote:
>
> > > In article
> > > <····································@x8g2000yqk.googlegroups.com>,
>
> > >  Francogrex <······@grex.org> wrote:
> > > > Hi  question about a code for drawing a histogram:
>
> > > > (setf count (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76 78 49
> > > > 18 8 36 15))
>
> > > > (setf br (list 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
> > > > 1967 1968 1969 1970
> > > >           1971 1972 1973 1974 1975 1976 1977 1978 1979))
>
> > > > (setf str2 (open "C:/histo.txt" :direction :output))
> > > > (dotimes (i (length count))
> > > >   (format str2 "~A ~A~%" (loop repeat  (nth i count) do (format str2
> > > > "*")) (nth i br)))
> > > > (close str2)
>
> > > > [content of histo.txt"]
>
> > > > **********NIL 1956
> > > > NIL 1957
> > > > ***********NIL 1958
> > > > *******NIL 1959
> > > > ************NIL 1960
> > > > ***********NIL 1961
> > > > **************************************************************NIL 1962
> > > > ***********************NIL 1963
> > > > etc...
>
> > > > But I don't want that it prints NIL. How can I write the code so that
> > > > the output is more like this:
> > > > 1956 **********
> > > > 1957
> > > > 1958 ***********
> > > > etc...
>
> > > ? (let ((c (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76 78 49 18 8 36 15))
> > >         (b (list 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
> > >                  1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979)))
> > >     (loop for c1 in c and b1 in b
> > >       do (print b1) (princ " ") (loop repeat c1 do (write-char #\*))))
>
> > Nothing so bloated as "loop" is needed.  In fact, no looping is
> > needed.
>
> > Ruby:
>
> > c = %w( 10 0 11 7 12 11 62 23 28 29 46 70
> >         16 37 8 3 76 78 49 18 8 36 15).map{|s| s.to_i}
>
> To create a vector of integers?
>
> #(10 0 11 7 12 11 62 23 28 29 46 70 37 8 3 76 78 49 18 8 36 15)
>
> > first_year = 1956
> > b = (first_year ... first_year + c.size)
> > puts b.zip(c).map{|yr,cnt| "#{yr} #{'*' * cnt}"}
>
> you zip the to vectors to a new vector of vectors?
> you map of the vectors to create strings?
> Which then you have to iterate over again to print it?
>
> That's a Ruby Goldberg Machine!  (http://www.rubegoldberg.com/)
>
> Lisp looks nice.
>
> ? (histogram 1956 (list 10 0 11 7 12 11 62 23 28 29 46 70 16 37 8 3 76
> 78 49 18 8 36 15))
>
> 1956  **********
> 1957
>
> ...
>
> ? (defun histogram (start list &aux (i (1- start)))
>     (mapc (lambda (c) (print (incf i)) (princ " ") (loop repeat c do
> (princ '*))) list))
> HISTOGRAM
>
> As a bonus it is interactively compiled to machine code...
>
> ? (disassemble 'histogram)
> L0
>   (leaq (@ (:^ L0) (% rip)) (% fn))
>   (cmpw ($ 16) (% nargs))                         ;[7]
>   (je.pt L17)                                     ;[12]
>   (uuo-error-wrong-number-of-args)                ;[15]
> L17
>   (pushq (% rbp))
>   (movq (% rsp) (% rbp))                          ;[18]
>   (pushq (% arg_y))                               ;[21]
>   (pushq (% arg_z))                               ;[22]
>   (pushq (% save0))                               ;[23]
>   (pushq (% save1))                               ;[25]
>   (pushq (% save2))                               ;[27]
>   (movq (@ -8 (% rbp)) (% arg_z))                 ;[29]
>   (testb ($ 7) (% arg_z.b))                       ;[33]
>   (jne L62)                                       ;[37]
>   (addq ($ -8) (% arg_z))                         ;[39]
>   (jno.pt L84)                                    ;[43]
>   (callq (@ .SPFIX-OVERFLOW))                     ;[46]
>   (leaq (@ (:^ L0) (% rip)) (% fn))               ;[53]
>   (jmp L84)                                       ;[60]
> L62
>   (movq ($ -8) (% arg_y))
>   (nop)                                           ;[69]
>   (callq (@ .SPBUILTIN-PLUS))                     ;[70]
>   (leaq (@ (:^ L0) (% rip)) (% fn))               ;[77]
> L84
>   (pushq (% arg_z))
>   (movq (@ -48 (% rbp)) (% arg_z))                ;[85]
>   (movl ($ 342) (% imm0.l))                       ;[89]
>   (movl ($ 3) (% imm1.l))                         ;[95]
>   (subq (% imm1) (@ (% gs) 216))                  ;[101]
>   (movq (@ (% gs) 216) (% temp0))                 ;[110]
>   (cmpq (@ (% gs) 224) (% temp0))                 ;[119]
>   (jg L132)                                       ;[128]
>   (uuo-alloc)                                     ;[130]
> L132
>   (movq (% imm0) (@ -13 (% temp0)))
>   (andb ($ 240) (@ (% gs) 216))                   ;[136]
>   (movq (% temp0) (% arg_y))                      ;[145]
>   (movq (% arg_z) (@ -5 (% arg_y)))               ;[148]
>   (movq (% arg_y) (@ -48 (% rbp)))                ;[152]
>   (movq ($ 1941) (% imm0))                        ;[156]
>   (movq ($ 51) (% imm1))                          ;[163]
>   (subq (% imm1) (@ (% gs) 216))                  ;[170]
>   (movq (@ (% gs) 216) (% temp0))                 ;[179]
>   (cmpq (@ (% gs) 224) (% temp0))                 ;[188]
>   (jg L201)                                       ;[197]
>   (uuo-alloc)                                     ;[199]
> L201
>   (movq (% imm0) (@ -13 (% temp0)))
>   (andb ($ 240) (@ (% gs) 216))                   ;[205]
>   (movq (% temp0) (% arg_z))                      ;[214]
>   (movq ($ 2666130979402886541) (% imm0))         ;[217]
>   (movb ($ 4) (@ -5 (% arg_z)))                   ;[227]
>   (movb ($ 76) (@ 2 (% arg_z)))                   ;[231]
>   (movq (% imm0) (@ 3 (% arg_z)))                 ;[235]
>   (movl ($ 5335077) (@ 11 (% arg_z)))             ;[239]
>   (movb ($ 242) (@ 19 (% arg_z)))                 ;[246]
>   (movq (@ '#<Anonymous Function #x300041C3536F> (% fn)) (% ra0)) ;
> [250]
>   (movq (@ -48 (% rbp)) (% arg_y))                ;[257]
>   (movq (% ra0) (@ 27 (% arg_z)))                 ;[261]
>   (movq (% arg_y) (@ 35 (% arg_z)))               ;[265]
>   (movq ($ 4429185024) (% arg_y))                 ;[269]
>   (movq (% arg_y) (@ 43 (% arg_z)))               ;[279]
>   (addq ($ 2) (% arg_z))                          ;[283]
>   (movq (% arg_z) (% save2))                      ;[287]
>   (movq (@ -16 (% rbp)) (% save0))                ;[290]
>   (movl ($ 12299) (% save1.l))                    ;[294]
>   (jmp L356)                                      ;[301]
> L303
>   (movq (@ -3 (% save0)) (% save0))
>   (movq (% save1) (% arg_z))                      ;[307]
>   (movq (% save2) (% temp0))                      ;[310]
>   (movw ($ 8) (% nargs))                          ;[313]
>   (movb (% temp0.b) (% imm0.b))                   ;[318]
>   (andb ($ 15) (% imm0.b))                        ;[320]
>   (cmpb ($ 14) (% imm0.b))                        ;[323]
>   (cmovgq (% temp0) (% temp1))                    ;[326]
>   (jge.pt L335)                                   ;[330]
>   (uuo-error-not-callable)                        ;[333]
> L335
>   (cmoveq (@ 10 (% temp0)) (% temp1))
>   (nop)                                           ;[340]
>   (nop)                                           ;[343]
>   (callq (% temp1))                               ;[346]
>   (leaq (@ (:^ L0) (% rip)) (% fn))               ;[349]
> L356
>   (movb (% save0.b) (% imm0.b))
>   (andb ($ 7) (% imm0.b))                         ;[359]
>   (cmpb ($ 3) (% imm0.b))                         ;[362]
>   (je.pt L370)                                    ;[365]
>   (uuo-error-reg-not-list (% save0))              ;[368]
> L370
>   (movq (@ 5 (% save0)) (% save1))
>   (cmpb ($ 11) (% save0.b))                       ;[374]
>   (jne L303)                                      ;[378]
>   (movq (@ -16 (% rbp)) (% arg_z))                ;[380]
>   (addq ($ 8) (% rsp))                            ;[384]
>   (popq (% save2))                                ;[388]
>   (popq (% save1))                                ;[390]
>   (popq (% save0))                                ;[392]
>   (leaveq)                                        ;[394]
>   (retq)                                          ;[395]

Folks, you should be nicer to William Jones:

An edited compilation of his posts and your replies would serve as a
good document for comparison of Ruby vs Lisp.  Being biased, I would
say the comparison would put Lisp into pretty good light (at least for
these types of problems).

Mirko
From: Alex Mizrahi
Subject: Re: Histogram in lisp?
Date: 
Message-ID: <49344a6b$0$90263$14726298@news.sunsite.dk>
 F> But I don't want that it prints NIL.

ever heard about conditional operators? IF, COND..?

in your case, OR will be fine:
 (or (loop repeat  (nth i count) do (format str2 "*"))
      "")

also, your code is more than messy. you need to learn about style