Removing white spaces from a list ?

Recommended Posts

Dear All,

I'm trying to find a loop for making substitutions in a list, for changing the ranges of a list of pitches.

SOME PITCHES (AND WHAT TO CHANGE)

```(setf pitches '(c4 d4 e4 c4 eb4 f4 c4 eb4 eb5))
(setf i '(c4 eb4))```

This will take out the range of the notes, i.e., c4 db5 will became c db

```(defun convert-pitch (pitches)
(loop for i in pitches
when (pitchp i)
collect (compress (butlast (explode i)))
else collect i))```

Setting a variable for pitches without range indication (pitnorng)

and a new range list

```(setf pitnorng (convert-pitch pitches))
(setf rangelist '(4 5 3 6 4))```

Function to put back the new range to the notes

```(defun convert-pitchbk (pitnorng)
(loop for i in pitnorng
when i
collect (flatten (mapcar 'list pitnorng rangelist)) else collect i
))```

Setting a collection of notes with new ranges:

`(setf convbaklst (convert-pitchbk pitnorng))`

The (problematic) result:

`((c 4 d 5 e 3 c 6 eb 4) (c 4 d 5 e 3 c 6 eb 4) (c 4 d 5 e 3 c 6 eb 4) (c 4 d 5 e 3 c 6 eb 4) (c 4 d 5 e 3 c 6 eb 4) (c 4 d 5 e 3 c 6 eb 4) (c 4 d 5 e 3 c 6 eb 4) (c 4 d 5 e 3 c 6 eb 4) (c 4 d 5 e 3 c 6 eb 4))`

I have WHITE SPACES between the note and the corresponding range...

LISP PROBLEM:

How to remove the white spaces ?

Best,

Julio

And also...

The list is multiplied 9 times... why?

Some problem in the loop function, I suppose...

Share on other sites
```(loop for i in (gen-divide 2 '(c 4 d 5 e 3 c 6 eb 4))
collect (compress i))

=> (c4 d5 e3 c6 eb4)```

i didn't read you posts precisely. only the last ONE ...but you could use COMPRESS...?

Share on other sites

Thanks a lot, André !

I´m trying to use your famous loops !

All the Best !

Happy 2019 !

Julio

Share on other sites

I will make the octave-map function work with octaves numbers as well.

```(octave-map '(c3 cs3 e5 f5 fs6 g5 gs4 a4 as3 b3)
'(c3 d3 e3 f3 g4 f4 e4 d4 c4 cs4))
=> (c3 d3 e5 f5 g6 f5 e4 d4 c3 cs3)

(octave-map '(3 3 5 5 6 5 4 4 3 3)
'(c3 d3 e3 f3 g4 f4 e4 d4 c4 cs4))
=> (c3 d3 e5 f5 g6 f5 e4 d4 c3 cs3)```

Share on other sites
1 hour ago, JulioHerrlein said:

Thanks a lot, André !

I´m trying to use your famous loops !

All the Best !

Happy 2019 !

Julio

i know, LOOPS are not very LISPian! but for me the most simple way "to think such processes" (more intuitive then recursion/iteration). and when the function/code is not to large it's not that important...

Share on other sites
21 minutes ago, opmo said:

I will make the octave-map function work with octaves numbers as well.

```
(octave-map '(3 3 7 5 6 6 7 7 7 3) '(c3 d3 e3 f3 g4 f4 e4 d4 c4 cs4))
=> (c3 d3 e7 f5 g6 f6 e7 d7 c7 cs3)```

Thank you Janusz ! Good Idea !

Happy 2019 !

Best,

Julio

Share on other sites

Janusz,

It would be great with some kind of span inside, like this:

```(octave-map '(3 5 6)
'(c3 d3 e3 f3 g3 f3 e3 d3 c3 cs3))

=> (c3 d5 e6 f3 g5 f6 e3 d5 c6 cs3)```

Best,

Julio

Or better:

```(octave-map '(3 5 6)
'(c3 d3 e3 f3 g3 f3 e3 d3 c3 cs3) :span t)

=> (c3 d5 e6 f3 g5 f6 e3 d5 c6 cs3)

Best, ```

Share on other sites
1 hour ago, AM said:

i know, LOOPS are not very LISPian! but for me the most simple way "to think such processes" (more intuitive then recursion/iteration). and when the function/code is not to large it's not that important...

Personally, i like very much to use the loop macro facilities, much clear and easy for me than recursion.

Also, I am a big fan of it because it is very powerful.

SB.

Share on other sites

This is how all functions work - with span or trim build in.

Share on other sites
45 minutes ago, opmo said:

This is how all functions work - with span or trim build in.

Beautiful

Share on other sites

Done in version 1.3.24409.

Share on other sites

Great, Janusz.

And no more manual updates !!

Best,

Julio

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

• Similar Topics

• By AM
very simple, i used something like this for my work... but is there somthing like this in OM?
greetings
andré

(defun sum-list-items* (somelists &key (each-step nil)) (let ((lista (car somelists)) (firstlist (car somelists))) (progn (setf somelists (loop for x in (rest somelists) collect (setf lista (loop for i in lista for j in x collect (+ i j))))) (if (equal each-step t) (append (list firstlist) somelists) (car (last somelists)))))) (sum-list-items* '((1 0 0 1) (1 0 0 0) (0 0 1 1))) (sum-list-items* '((1 0 0 1) (1 0 0 0) (0 0 1 1)) :each-step t) (sum-list-items* '((1 0 8 1) (2 0 0 0) (0 -1 3 1))) (sum-list-items* '((1 0 8 1) (2 0 0 0) (0 -1 3 1)) :each-step t)
• By AM
is there another way to code such a function/idea?
this is (at the moment) a "theoretically function"... no concret use - l'art pour l'art :-)
thanx for smarter LISP-code-IDEAS!
andré

;;; evaluate PROGN (as a reset) (progn (defstruct counter n) (defvar cnt) (setf cnt (make-counter :n -1)) (defun read-list-in-steps (alist) (nth (setf (counter-n cnt) (1+ (counter-n cnt))) alist))) ;;; evaluate a view times, so one value after the other will be in the output ;;; you have to evaluate the progn-seq before every new start!!! (read-list-in-steps '(1 2 3 4 5 6)) (read-list-in-steps '(c4 f4 e4 f4 g5))
• By AM
the "STEP-TO"-idea could be used more common... with other parameters...welcome to extend/develop it...
for mulidimensional/multiparametrical rnd-walks (first example)? :-)

;;; FUNCTION -> same as step-to-pitch (defun reading-list-by-steps (&key steps values start) (let ((pos (car (position-item start values)))) (append (list (nth pos values)) (loop for i in steps do (setf pos (+ pos i)) when (> pos (length values)) do (setf pos (+ 0 i)) collect (nth pos values))))) ;;; EXAMPLES ;;; rnd-walk all parameters (make-omn :length (reading-list-by-steps :steps (gen-walk 4 :start 1) :values '(1/32 2/32 3/32 4/32 5/32 6/32) :start 3/32) :pitch (reading-list-by-steps :steps (gen-walk 4 :start 2) :values (expand-tonality '(b3 messiaen-mode6)) :start 'ds4) :velocity (reading-list-by-steps :steps (gen-walk 4 :start 1) :values '(pppp ppp pp p mp mf f ff fff ffff) :start 'ppp) :articulation (reading-list-by-steps :steps (gen-walk 4 :start 1) :values '(ponte tasto spicc ord pizz snap) :start 'tasto)) ;;;; separeted examples (reading-list-by-steps :steps (gen-walk 4 :start 1) :values '(pppp ppp pp p mp mf f ff fff ffff) :start 'ppp) ;; => depends on rnd-walk values (reading-list-by-steps :steps '(1 1 -1 2 2 -1 1) :values '(a b c d e f g) :start 'b) ;; => (b c d c e g f g) (reading-list-by-steps :steps '(1 1 -1 2 2 -1 1) :values '(1/32 2/32 3/32 4/32 5/32 6/32) :start 3/32) ;; => (3/32 1/8 5/32 1/8 3/16 3/32 1/16 3/32) (reading-list-by-steps :steps '(1 1 -1 2 -1) :values '(ponte tasto spicc ord pizz snap) :start 'tasto) ;; => (tasto spicc ord spicc pizz ord)

×

• Lessons