Author Topic: Help! LIST  (Read 1796 times)

0 Members and 1 Guest are viewing this topic.

2e4lite

  • Guest
Help! LIST
« on: August 07, 2014, 03:58:16 AM »
        I need two functions to get the lists.  There is a  mode variable  as a globe variable of them .  The value of mode -1 is integer ,  1 one decimal , 2 two decimals , 5 a multiple of 5.

One :
 a known list:
Code: [Select]
'(0     1.44   1.55   1.99    10      10.4     10.8    100.444   100.555)The function can get  a list to following if the mode is -1
Code: [Select]
'(0      2        2        2        10        11        11     101    101)The function can get a list to following if the  mode is 1
Code: [Select]
'(0.0     1.5     1.6      2.0     10.0     10.4      10.8    100.5   100.6)The function can get list to following if the  mode is 2
Code: [Select]
'(0.00   1.44   1.55    1.99   10.00    10.40   10.80     100.50    100.60)The function can get a list to following if the  mode is 5
Code: [Select]
'(0        5         5        5      10      15       15    105   105)
Another:
 a known list:
Code: [Select]
'(0      1.44   1.55   1.99   10      10.4   10.8    100.444  100.555)The function can get list to following if the  mode is -1
Code: [Select]
'(0       1        1       1       10       10       10      100     100)The function can get list to following if the  mode is 1
Code: [Select]
'(0.0   1.4      1.5     1.9    10.0    10.4    10.8     100.4     100.5)The function can get list to following if the  mode is 2
Code: [Select]
'(0.00  1.44   1.55   1.99  10.00  10.40  10.80   100.44    100.55)The function can get list to following if the  mode is 5
Code: [Select]
'(0       0        0       0       10       10       10       100     100)
Who can help me?
Thanks in advance!
« Last Edit: August 07, 2014, 10:10:14 PM by 2e4lite »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help! LIST
« Reply #1 on: August 07, 2014, 05:22:14 AM »

What code have you tried ??

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: Help! LIST
« Reply #2 on: August 07, 2014, 01:33:57 PM »
Here are two functions to round a numerical argument up or down to the next 'm':

Code - Auto/Visual Lisp: [Select]
  1. ;; Round Up  -  Lee Mac
  2. ;; Rounds 'n' up to the nearest 'm'
  3.  
  4. (defun LM:roundup ( n m )
  5.     (cond
  6.         ((equal 0.0 (rem n m) 1e-8) n)
  7.         ((< n 0) (- n (rem n m)))
  8.         ((+ n (- m (rem n m))))
  9.     )
  10. )
Code - Auto/Visual Lisp: [Select]
  1. ;; Round Down  -  Lee Mac
  2. ;; Rounds 'n' down to the nearest 'm'
  3.  
  4. (defun LM:rounddown ( n m )
  5.     (cond
  6.         ((equal 0.0 (rem n m) 1e-8) n)
  7.         ((< n 0) (- n (rem n m) m))
  8.         ((- n (rem n m)))
  9.     )
  10. )

Apply the above to your lists using mapcar and you are done.

2e4lite

  • Guest
Re: Help! LIST
« Reply #3 on: August 07, 2014, 09:41:43 PM »
  Thanks Lee Mac. Your reply is efficient and quick! I've already tested it .The result showed that it indeed  the same as your reply .

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help! LIST
« Reply #4 on: August 07, 2014, 11:27:47 PM »
I haven't tried, but
I can't see those generic functions mutating the lists as required.

2e4lite,
can you show how you've used them and the result?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.