Author Topic: count up  (Read 1397 times)

0 Members and 1 Guest are viewing this topic.

Hugo

  • Bull Frog
  • Posts: 433
count up
« on: January 05, 2012, 10:10:27 AM »
Hello

Can I change a the Lisp so it works well with less.
Will not tolerate it.
Thank you
100.1/10
100.1/9
100.1/09

Hallo

Kann mir einer das Lisp so ändern das es auch mit minus funktioniert.
Bekomme das nicht hin.
Danke

Code: [Select]
;; INCSUFF -Gilles Chanteau- 2008/01/15
;; Adds the specified increment to a string suffix.
;; Is considered as suffix, all [0-9], [A-Z] and [a-z] characters from
;; the end of the string according to flag value.
;;
;; Arguments
;; str : a string
;; inc : a positive integer
;; flag : an integer, the sum of following binary codes
;;       1 for numbers [0-9]
;;       2 for uppercase  [A-Z]
;;       4 for lowercase [a-z]
;;
;; Return
;; The string with incremented suffix (or nil if none valid suffix)
;;
;; Examples :
;; (incsuff "N° 002" 12 1) = "N° 014"
;; (incsuff "Drawing_A" 1 1) = "Drawing_B"
;; (incsuff "test_ZZ9" 1 3) = "test_AAA0"
;; (incsuff "test_ZZ9" 1 1) = "test_ZZ10"
;; (incsuff "12-" 1 nil) = nil
;;
;; Update (13/02/08) : binary codes

(defun incsuff (str inc flag / lst crt pas ind dep quo ret)
  (setq lst (reverse (vl-string->list str)))
  (while
    (and
      (setq crt (car lst))
      (cond
((< 47 crt 58)
(setq pas 10
       ind 48
)
)
((and flag (< 64 crt 91))
(setq pas 26
       ind 65
)
)
((and flag (< 96 crt 123))
(setq pas 26
       ind 97
)
)
((< 0 quo)
(setq crt (if (= 10 pas)
     ind
     (1- ind)
   )
       lst (cons (car lst) lst)
)
)
      )
    )
     (setq dep (- crt ind)
   quo (/ (+ dep inc) pas)
   ret (cons (+ ind (rem (+ dep inc) pas)) ret)
     )
     (if (zerop quo)
       (setq ret (append (reverse (cdr lst)) ret)
     lst nil
       )
       (if (cdr lst)
(setq lst (cdr lst)
       inc quo
)
(setq lst (list ind)
       inc (if (= 10 pas)
     quo
     (1- quo)
   )
)
       )
     )
  )
  (if ret
    (vl-list->string ret)
  )
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: count up
« Reply #1 on: January 05, 2012, 06:07:52 PM »
Show the before and after of what you want for a result.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Hugo

  • Bull Frog
  • Posts: 433
Re: count up
« Reply #2 on: January 06, 2012, 04:47:55 AM »
Hello

before   "100.1/10"
after     "100.1/9   and "100.1/09"

before  "100.1/02"
after     "100.1/01"

before "100.1/2"
after   " 100.1/1"

Danke

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: count up
« Reply #3 on: January 06, 2012, 09:06:08 AM »
Oh, you want to subtract the suffix.
Like this
Code: [Select]
(incsuff "100.1/02" -1 1)
"100.1/01"
I see it doesn't work in all cases.
Code: [Select]
(incsuff "100.1/10" -1 1)
"100.1/1/"
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: count up
« Reply #4 on: January 06, 2012, 09:29:56 AM »
The routine would need to be reworked to handle negative values
but this is a start:
 replace this
Code: [Select]
        ((< 47 crt 58) ; numbers
           (setq pas 10
                 ind 48
           )
        )
with this:
Code: [Select]
        ((< 47 crt 58) ; numbers
         (if (minusp inc)
           (setq pas 10
                 ind 57
           )
           (setq pas 10
                 ind 48
           )
         )
        )

This is not a complete solution.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Hugo

  • Bull Frog
  • Posts: 433
Re: count up
« Reply #5 on: January 06, 2012, 10:16:22 AM »
@CAB
Thank you
This is the best forum  :-) :-) :-)
Danke

Das ist das beste Forum
« Last Edit: January 06, 2012, 11:54:00 AM by Hugo »