series-users — Users' discussion list

You can subscribe to this list here.

 2002 2005 2008 2010 2013 Jan Feb (1) Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan (4) Feb Mar Apr May Jun Jul Aug Sep Oct Nov (1) Dec (19) Jan Feb Mar Apr May Jun (1) Jul Aug (7) Sep Oct Nov Dec Jan Feb Mar Apr May Jun Jul (15) Aug Sep Oct Nov Dec Jan (2) Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

Showing results of 50

<< < 1 2 (Page 2 of 2)
 Re: [Series-users] How to write series-tail From: - 2005-12-19 15:35:50 ```>>>>> "Chris" == Chris Dean writes: Chris> [Looks like I'm on a roll with all these questions!] Chris> How do I write a function to return the last N elements of a series? Chris> I'd prefer that the result of this function be a series itself. Chris> Here's one way that doesn't really work: Chris> (defun series-tail (items &optional (how-many 1)) Chris> (declare (optimizable-series-function 1)) Chris> (let ((len (collect-length items))) Chris> (if (<= 0 how-many len) Chris> (subseries items (- len how-many)) Chris> items))) Chris> I suppose I could keep a ring of the last HOW-MANY elements, but I'm Chris> not sure how to do that. Not sure if this is exactly what you want, but here is a function that takes a series and returns a new series whose elements are a list of the last N elements seen thus far. (defun series-tail (items how-many) (declare (optimizable-series-function 1)) (#Mreverse (collecting-fn t #'(lambda () (make-list 0)) #'(lambda (r x) (values (subseq (cons x r) 0 how-many) (cons x r))) items))) (series-tail (scan-range :below 10) 3) => #Z((0) (0 1) (0 1 2) (1 2 3) (2 3 4) (3 4 5) (4 5 6) (5 6 7) (6 7 8) (7 8 9)) And if you really want the last set, then (collect-last (series-tail (scan-range :below 10) 3)) => (7 8 9) or even (scan (collect-last (series-tail (scan-range :below 10) 3))) if you want a series. This implementation does generate quite a bit of garbage because it does cons up new lists for each iteration. Ray ```
 Re: [Series-users] How to write series-tail From: Chris Dean - 2005-12-19 11:38:55 ```"Hoehle, Joerg-Cyril" writes: > (map-fn t #'ring-ref (scan-range :below (ring-current-length ring))) Very nice! With your change: (defun scan-ring (ring) (declare (optimizable-series-function 1)) (map-fn t (lambda (i) (ring-ref ring i)) (scan-range :below (ring-current-length ring)))) We produce very efficient code. >>(defun ring->list (ring) >> "Convert the ring to a list" >> (collect (scan-ring ring))) > This looks more like a testsuite -- create a throw-away series just > to get the values?! Why not just (coerce 'list (ring-vec ring))? One reason is that (coerce (ring-vec ring) 'list) doesn't always give me the correct order - that is, the 0th index of the vector might not be the first element in the ring. The main reason though is that Series is very good at using a throw-away series. The efficiency of that one line is on par with a hand coded DO loop. That, to me, is the main point of series: High level descriptive code that runs as efficiently as something I've hand coded. Regards, Chris Dean ```
 Re: [iterate-devel]/[series-users] collect-tail ? From: Chris Dean - 2005-12-19 10:59:25 ```"Hoehle, Joerg-Cyril" writes: > a) Either take a code generation approach and create code that latches > (= delay by one) N times, > > b) Or take a functional approach, implement a ring datastructure and > use that. Thanks for the great advice. This is the same reasoning I used. I have since implemented collect-tail and series-tail using a ring and I will say that it was more straight forward to write collect-tail for the iterate system. > since you're asking similar questions in series-users and > iterate-devel, This is my standard looping question in any language: Read the last N lines of a file, transform them, filter them, and return the unique elements. This is a nice test because (to use Series lingo I didn't know until recently) it combines on-line and off-line processing. > I'm starting to wonder whether you're going to write a paper on > comparisons of some looping frameworks? :-) :-) Some papers one might wish to read are the recent Shivers paper [1] and the Egner paper [2]. They provide a decent overview from a Scheme perspective. These papers don't really go into the use of iterators/generators ala Python, Ruby, and CLU. (This is the approach where one uses yield in the generator to return control to the loop.) It's too bad they don't delve into iterators because it is a very elegant approach to the problem (albeit with some performance hurdles). It would be an interesting problem to write a performant iterator system in Common Lisp. Thanks again, Chris Dean Footnotes: [1] The anatomy of a loop: a story of scope and control. Olin Shivers. http://www.cc.gatech.edu/~shivers/citations.html#loop [2] Eager Comprehensions in Scheme: The design of SRFI-42 Sebastian Egner http://www.deinprogramm.de/scheme-2005/program.html ```
 Re: [Series-users] How to write series-tail From: Hoehle, Joerg-Cyril - 2005-12-19 10:35:04 ```Chris Dean writes: >I eagerly await a code critique. >(defun scan-ring (ring) > "Return the ring as a series." > (declare (optimizable-series-function)) > (let ((i 0) (len (ring-current-length ring))) > (scan-fn t > (lambda () (and (/= i len) (ring-ref ring i))) > (lambda (x) (declare (ignore x)) (ring-ref ring (incf i))) > (lambda (x) (declare (ignore x)) (= i len))))) I think you somewhat misued scan-fn here. Scan-fn allows to write purely functional code. In order to achieve this, it passes state around explicitly. This is what the init function is for, and the first values of the step and test functions. In effect, scan-fn is very similar to REDUCE with :INITIAL-VALUE, or the fold procedure in functional programming. The (INCF i) and DECLARE IGNORE is IMHO a sign of the misuse. Here's my solution (untested): (map-fn t #'ring-ref (scan-range :below (ring-current-length ring))) >(defun ring->list (ring) > "Convert the ring to a list" > (collect (scan-ring ring))) This looks more like a testsuite -- create a throw-away series just to get the values?! Why not just (coerce 'list (ring-vec ring))? Regards, Jorg Hohle. ```
 Re: [iterate-devel]/[series-users] collect-tail ? From: Hoehle, Joerg-Cyril - 2005-12-19 09:41:47 ```Chris, since you're asking similar questions in series-users and iterate-devel, I'm starting to wonder whether you're going to write a paper on comparisons of some looping frameworks? :-) >how do I go about collecting the last N elements of anything? > (iter (for line :in-file my-file :using #'read-line) > (collect-tail line :how-many 10)) If 10 is known at macro-expansion time, you can always write a macro that expands to a series of 10 uses of PREVIOUS in Iterate, or 10 consecutive latches in Series. I.e., IMHO there are always two ways, either with series of iterate: a) Either take a code generation approach and create code that latches (= delay by one) N times, b) Or take a functional approach, implement a ring datastructure and use that. The former looks like a better use of Series: it could be a series of the 10 last values (as a list, or 10 series of values farther and farther behind). In/After the last iteration, you'll have the 10 last values. As to which approach is better... Probably you wouldn't want to generate code for the last 100 values. BTW, you'll have to defined what happens when less than 10 iterations were taken. Straight-forward code is likely to return (val1 val2 nil nil ...6xnil), whereas one could wish for (val1 val2) with only 2 iterations. Regards, Jorg Hohle. ```
 Re: [Series-users] How to write series-tail From: Chris Dean - 2005-12-15 08:01:27 ```Chris Dean writes: > How do I write a function to return the last N elements of a series? > I'd prefer that the result of this function be a series itself. Here's one way. Assume a ring data structure and only keep the last N elements: (defun series-tail (items how-many) "Returns the last HOW-MANY elements of the series ITEMS. If HOW-MANY is greater than (collect-length ITEMS) then all of the elements in ITEMS are returned." (declare (optimizable-series-function 1) (off-line-port items)) (let ((ring (make-ring how-many))) (iterate ((x items)) (ring-enqueue ring x)) (scan-ring ring))) I eagerly await a code critique. If found this very difficult to write, mostly due to the cryptic (to me) error messages. However, once it was done it looks very nice and elegant. Using series-tail makes the series expression not parallelizable which is expensive, but no more expensive than another non-series looping construct. (The ring code is below for those interested.) Regards, Chris Dean ;;; ;;; rings ;;; (defstruct (ring (:constructor make-ring-storage)) size index current-length vec) (defun make-ring (size) "Create a ring. A ring is like a fixed sized queue except that when the ring is full and an element is inserted, the oldest element is deleted to make room. SIZE is the size of the ring." (make-ring-storage :size size :index 0 :current-length 0 :vec (make-array size))) (defun ring-enqueue (ring obj) "Add a new element to the ring. The oldest element in the ring may be deleted to make room." (with-slots (size index current-length vec) ring (setf (svref vec index) obj) (setf index (mod (1+ index) size)) (setf current-length (min size (1+ current-length))) obj)) (defun ring-dequeue (ring) "Remove the oldest element from the ring. It is an error to remove from an empty ring." (when (ring-empty? ring) (error "ring is empty")) (prog1 (ring-ref ring 0) (decf (ring-current-length ring)))) (defun ring-ref (ring i) "Get the element at the index I. The oldest element is index 0." (with-slots (size index current-length vec) ring (let ((ii (mod (+ i (- index current-length)) size))) (svref vec ii)))) (defun ring-empty? (ring) (zerop (ring-current-length ring))) (defun ring-full? (ring) (= (ring-current-length ring) (ring-size ring))) (defun scan-ring (ring) "Return the ring as a series." (declare (optimizable-series-function)) (let ((i 0) (len (ring-current-length ring))) (scan-fn t (lambda () (and (/= i len) (ring-ref ring i))) (lambda (x) (declare (ignore x)) (ring-ref ring (incf i))) (lambda (x) (declare (ignore x)) (= i len))))) (defun ring->list (ring) "Convert the ring to a list" (collect (scan-ring ring))) ```
 Re: [Series-users] collect-series ? From: Chris Dean - 2005-12-13 19:07:53 ```Raymond Toy writes: > Chris> Is there a way to use gathering to collect a series? ... > I'm not at all familiar with the generator/gather part of series. > I'll have to think about this. Do you need to do it this way instead > of using series itself? I'm searching for the "right way" to handle the problem, so another way would be fine but the gathering code seemed like a natural fit. I used to have this code that returned a list of URLs from a string: (defun html-body->raw-urls (body &key use-javascript) (let ((res nil)) (do-scans (s e rs re *AHREF-RE* body) (push (subseq body (aref rs 0) (aref re 0)) res)) (do-scans (s e rs re *ANY-URL-RE* body) (push (subseq body (aref rs 0) (aref re 0)) res)) (when use-javascript (do-scans (s e rs re *JS-RE* body) (push (subseq body (aref rs 0) (aref re 0)) res))) res)) What I'd like to do is replace it with this code that returns a series: (defun html-body->raw-urls (body) (scan (gathering ((res collect)) (cl-ppcre:do-scans (s e rs re *AHREF-RE* body) (next-out res (subseq body (aref rs 0) (aref re 0)))) (cl-ppcre:do-scans (s e rs re *ANY-URL-RE* body) (next-out res (subseq body (aref rs 0) (aref re 0)))) (when use-javascript (do-scans (s e rs re *JS-RE* body) (next-out res (subseq body (aref rs 0) (aref re 0)))))))) If you can suggest any natural way of doing this, that would be wonderful. Regards, Chris Dean ```
 Re: [Series-users] Re: coerce-maybe-fold error while compiling under LispWorks From: Chris Dean - 2005-12-13 18:46:46 ```toy@... writes: > With this change, does LW run the testsuite correctly now? Hmm. I'm not sure. I did get a break and this message when running do-tests: Restriction violation 6 in series expression: NIL The form LOAD-TIME-VALUE not allowed in SERIES expressions. If I just continued from that break and everything else seemed ok. Output below. Regards, Chris Dean Doing 563 pending tests of 563 tests total. Type a string representing a pathname of a scratch disk file: "~/tmp/foo.scratch2" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 487 488 489 490 491 492 493 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 553 554 555 556 557 558 Restriction violation 6 in series expression: NIL The form LOAD-TIME-VALUE not allowed in SERIES expressions. Warning: 559 560 561 1000 1001 3000 5000 5001 5002 5003 5004 No tests failed. T ```
 Re: [Series-users] delete-duplicates equivalent From: Hoehle, Joerg-Cyril - 2005-12-13 17:56:44 ```Raymond Toy wrote: >>>>>> "Chris" == Chris Dean writes: > Chris> (delete-duplicates '("3" "1" "4" "1" "5" "9") >:test #'string-equal) > Chris> => ("3" "4" "1" "5" "9") > Chris> What's the equivalent idiom in series? Should I just write > Chris> series-delete-duplicates? >Off the top of my head, I don't think you can. I believe otherwise. I think there must be such an idiom somewhere in series (I haven't used it for quite some time now). Because IIRC, the a-list and p-list converters are documented to do so (IIRC, just for one of the directiones). Thus I suppose that another collector with variable predicates can be built, modeled after the present a-list and p-list processing functions. Actually, when I read the documentation, I was surprised by this behaviour since it's more expensive than a simple mapping of a list (in either a-list or p-list format) to the series of keys and values, disregarding duplicates. Regards, Jorg Hohle. ```
 Re: [Series-users] Re: coerce-maybe-fold error while compiling under LispWorks From: - 2005-12-13 14:39:54 ```>>>>> "Chris" == Chris Dean writes: Chris> Chris Dean writes: >> I'm trying to compile Series 2.2.9 under LispWorks and am getting this >> error Chris> ... Chris> Looks like coerce-maybe-fold needed a eval-when around it. Patch Chris> below. With this change, does LW run the testsuite correctly now? Ray ```
 Re: [Series-users] collect-series ? From: - 2005-12-13 13:56:00 ```>>>>> "Chris" == Chris Dean writes: Chris> Is there a way to use gathering to collect a series? For example, Chris> here's a function that uses gathering and scan to produce a series as Chris> a result: Chris> (defun foo () Chris> (scan (gathering ((res collect)) Chris> (next-out res 1) Chris> (next-out res 2) Chris> (next-out res 3)))) [snip] I'm not at all familiar with the generator/gather part of series. I'll have to think about this. Do you need to do it this way instead of using series itself? Ray ```
 Re: [Series-users] How to write series-tail From: - 2005-12-13 13:54:57 ```>>>>> "Chris" == Chris Dean writes: Chris> [Looks like I'm on a roll with all these questions!] Chris> How do I write a function to return the last N elements of a series? Chris> I'd prefer that the result of this function be a series itself. Chris> Here's one way that doesn't really work: Chris> (defun series-tail (items &optional (how-many 1)) Chris> (declare (optimizable-series-function 1)) Chris> (let ((len (collect-length items))) Chris> (if (<= 0 how-many len) Chris> (subseries items (- len how-many)) Chris> items))) I don't think you can do that because you don't know how long the series is until you traverse it. I suppose you could keep a list of the last N elements as you traverse it so you have the last N at any point as you traverse the list, but I suspect this isn't what you really want. Ray ```
 Re: [Series-users] delete-duplicates equivalent From: Raymond Toy - 2005-12-13 13:50:06 ```>>>>> "Chris" == Chris Dean writes: Chris> The delete-duplicates function has the nice feature of being able to Chris> define test to compare elements: Chris> (delete-duplicates '("3" "1" "4" "1" "5" "9") :test #'string-equal) Chris> => ("3" "4" "1" "5" "9") Chris> What's the equivalent idiom in series? Should I just write Chris> series-delete-duplicates? Off the top of my head, I don't think you can. To delete the duplicates (naively), you have to scan the list several times, or keep additional information, or sort it. Series doesn't like that. I think I'd just collect the series, delete the duplicates, and scan the list again. Ray ```
 [Series-users] How to write series-tail From: Chris Dean - 2005-12-13 03:01:06 ```[Looks like I'm on a roll with all these questions!] How do I write a function to return the last N elements of a series? I'd prefer that the result of this function be a series itself. Here's one way that doesn't really work: (defun series-tail (items &optional (how-many 1)) (declare (optimizable-series-function 1)) (let ((len (collect-length items))) (if (<= 0 how-many len) (subseries items (- len how-many)) items))) I suppose I could keep a ring of the last HOW-MANY elements, but I'm not sure how to do that. Thanks again! Regards, Chris Dean ```
 [Series-users] delete-duplicates equivalent From: Chris Dean - 2005-12-13 00:00:01 ```The delete-duplicates function has the nice feature of being able to define test to compare elements: (delete-duplicates '("3" "1" "4" "1" "5" "9") :test #'string-equal) => ("3" "4" "1" "5" "9") What's the equivalent idiom in series? Should I just write series-delete-duplicates? I can't use (collect 'set ...) because it doesn't take a :test or :key parameter. Regards, Chris Dean ```
 Re: [Series-users] Re: coerce-maybe-fold error while compiling under LispWorks From: - 2005-12-12 14:02:16 ```>>>>> "Chris" == Chris Dean writes: Chris> Chris Dean writes: >> I'm trying to compile Series 2.2.9 under LispWorks and am getting this >> error Chris> ... Chris> Looks like coerce-maybe-fold needed a eval-when around it. Patch Chris> below. Sorry for the long delay. I'll apply this patch very soon. And thanks for testing this with Lispworks! Ray ```
 [Series-users] collect-series ? From: Chris Dean - 2005-12-09 20:40:20 ```Is there a way to use gathering to collect a series? For example, here's a function that uses gathering and scan to produce a series as a result: (defun foo () (scan (gathering ((res collect)) (next-out res 1) (next-out res 2) (next-out res 3)))) Even if it just syntactic sugar, I'd rather type something like (defun foo2 () (gathering ((res collect-series)) (next-out res 1) (next-out res 2) (next-out res 3))) Thanks for any pointers. Regards, Chris Dean ```
 [Series-users] Re: coerce-maybe-fold error while compiling under LispWorks From: Chris Dean - 2005-12-09 19:39:19 ```Chris Dean writes: > I'm trying to compile Series 2.2.9 under LispWorks and am getting this > error ... Looks like coerce-maybe-fold needed a eval-when around it. Patch below. Regards, Chris Dean --- s-code.lisp.orig 2005-11-15 07:07:57.000000000 -0800 +++ s-code.lisp.new 2005-12-08 20:34:06.000000000 -0800 @@ -1452,8 +1452,9 @@ ) ; end of eval-when #-allegro -(defmacro coerce-maybe-fold (thing type) - `(coerce ,thing ,type)) +(eval-when (:compile-toplevel :load-toplevel :execute) + (defmacro coerce-maybe-fold (thing type) + `(coerce ,thing ,type))) #+allegro ```
 [Series-users] coerce-maybe-fold error while compiling under LispWorks From: Chris Dean - 2005-12-03 10:32:42 ```I'm trying to compile Series 2.2.9 under LispWorks and am getting this error: **++++ Error in SERIES:SCAN: Undefined function COERCE-MAYBE-FOLD called with arguments ((COERCE-MAYBE-FOLD 0 VAR-TYPE) # #) fenv ((#:SOURCE-LEVEL-ENVIRONMENT-MARKER . #)>) (#:FUNCTOR-MARKER . #)) (DECLARE (HARLEQUIN-COMMON-LISP:LAMBDA-NAME INIT-ELEM)) (COMMON-LISP:LET (#) (COND # # # # # # # #)))>)) benv NIL tenv NIL decl NIL>). Is this typical? I tried just to used asdf to load it like I normally do, and when that didn't work I followed the instructions in the RELEASE-NOTES. Both time I got the same error. Any advice on how to fix this? I'm running LispWorks 4.4.5 on Mac OS X. Thanks! Regards, Chris Dean ```
 [Series-users] Loading series fails on recent sbcl From: Joel Boehland - 2005-11-10 21:50:23 ```Note: I sent this message earlier to series-bugs, but it was held up for administrative approval. Raymond Toy asked that I resend to the list for archival purposes. ====================================================== Hi, When trying to load the system definition for series in a recent sbcl (0.9.5 linux x86-64), I get the following error: ### symbol SERIES:SERIES cannot be both the name of a type and the name of a declaration [Condition of type SB-KERNEL:DECLARATION-TYPE-CONFLICT-ERROR] See also: Common Lisp Hyperspec, 3.8.21 [section] ### It looks like the change added to sbcl that causes this error to be thrown was added around the end of May. From the Changelog: ### 2005-05-31 23:06 jsnell * NEWS, package-data-list.lisp-expr, version.lisp-expr, src/code/condition.lisp, src/compiler/globaldb.lisp, src/pcl/boot.lisp: 0.9.1.9: Fix a few ansi-test failures. Symbols can't be both the name of a type and the name of a declaration (ANSI 3.8.21). ### Hope this information is useful. Thanks, Joel ```
 Re: [Series-users] Alteration not working for my scanner. From: Dirk Gerrits - 2005-01-27 21:26:07 ```Raymond Toy writes: > I've checked in the changes. Let me know how it goes. (Might have to > wait a day for anoncvs to catch up.) Oh I forgot to ask: should I create a CVS snapshot package for Gentoo Linux, or will these changes be in an official release in the foreseeable future? Kind regards, Dirk Gerrits ```
 Re: [Series-users] Alteration not working for my scanner. From: Dirk Gerrits - 2005-01-27 21:19:01 ```Raymond Toy writes: > I've checked in the changes. Let me know how it goes. (Might have to > wait a day for anoncvs to catch up.) Seems to work fine in both CMUCL and SBCL. Thanks again. Kind regards, Dirk Gerrits ```
 Re: [Series-users] Alteration not working for my scanner. From: Dirk Gerrits - 2005-01-26 22:13:13 ```Raymond Toy writes: > I do think there is a problem with your code. > > SCAN-VEC should probably be written as > > (defun scan-vec (vec) > (declare (optimizable-series-function)) > (to-alter (make-series (vec-x vec) (vec-y vec) (vec-z vec)) > #'(lambda (new-value index v) > (ecase index > (0 (setf (vec-x v) new-value)) > (1 (setf (vec-x v) new-value)) > (2 (setf (vec-x v) new-value)))) > (scan-range :from 0) > (make-series vec vec vec))) > > I don't think the function can capture variables, so you need to pass > in the desired variable. Oh I didn't know that. But passing the extra series is not much of a problem... By the way, any particular reason to use (make-series vec vec vec) instead of (series vec)? > (Plus there's a typo. vec-x is used 3 times, but you probably wanted > vec-y and vec-z.) Oops... :) > With the above change and my fix for series, > > (let ((vec (make-vec :x 1 :y 2 :z 3))) > (alter (scan-vec vec) (series 0)) > vec) > > will return #s(vec :x 0 :y 0 :z 0) now. > > I need to run some tests and I'll let you know when I've updated the > cvs sources. Cool, thanks. I guess I'll hear from you then. Kind regards, Dirk Gerrits ```
 [Series-users] Alteration not working for my scanner. From: Dirk Gerrits - 2005-01-16 15:43:02 ```Hi, does anyone know what I'm doing wrong in the following code? I'm trying to make a scanner for a 3D vector data structure that supports alteration. As you can see the scanning works fine, but ALTER has no effect: > (defstruct vec x y z) VEC > (defun scan-vec (vec) (declare (optimizable-series-function)) (to-alter (make-series (vec-x vec) (vec-y vec) (vec-z vec)) #'(lambda (new-value index) (ecase index (0 (setf (vec-x vec) new-value)) (1 (setf (vec-x vec) new-value)) (2 (setf (vec-x vec) new-value)))) (scan-range :from 0))) SCAN-VEC > (collect (scan-vec (make-vec :x 1 :y 2 :z 3))) (1 2 3) > (let ((vec (make-vec :x 1 :y 2 :z 3))) (alter (scan-vec vec) (series 0)) vec) #S(VEC :X 1 :Y 2 :Z 3) ; <-- should be #S(VEC :X 0 :Y 0 :Z 0) I'm using the dev-lisp/cl-series-2.2.7 package in Gentoo Linux. This contains some patches of mine to make it work for SBCL, but I've also tried the above in CMUCL with the same results. Thanks in advance for any help. Kind regards, Dirk Gerrits ```
 [Series-users] series problems with multiple values From: Hoehle, Joerg-Cyril - 2002-02-18 14:17:04 ```Dear users of the series package, I thought reimplementing lots of functions (here SCAN-ALIST) would help in getting used to series... Let's gradually start with: (defun my-scan-alist (alist &optional (test #'eql)) (declare (optimizable-series-function 1)) ;is needed (declare (off-line-port 0)) (let* ((assoc (choose-if #'consp (scan alist))) (keys (#Mcar assoc)) ;;(vals (#Mcdr assoc)) (bools (map-fn t (unseen-before :test test) keys))) (choose bools keys))) MY-SCAN-ALIST However I need to return two values (like scan-plist and scan-alist = do): Restriction violation 7 in series expression: (DEFUN MY-SCAN-ALIST (ALIST &OPTIONAL (TEST #'EQL)) (DECLARE (OPTIMIZABLE-SERIES-FUNCTION 2)) (DECLARE (OFF-LINE-PORT 0 1)) (LET* ((ASSOC (CHOOSE-IF #'CONSP (SCAN ALIST))) (KEYS (SERIES::|#M| CAR ASSOC)) (VALS (SERIES::|#M| CDR ASSOC)) (BOOLS (MAP-FN T (UNSEEN-BEFORE :TEST TEST) KEYS))) (VALUES (CHOOSE BOOLS KEYS) (CHOOSE BOOLS VALS)))) VALUES returns multiple series: (VALUES (CHOOSE BOOLS KEYS) (CHOOSE BOOLS VALS)) WARNING: MY-SCAN-ALIST [568]>=20 What's this obvious message? Of course VALUES returns 2 values, which are both series. The user manual (MIT memo) talks p.52 about using COTRUNCATE to indicate that the two output series are in sync. I obtain: Restriction violation 22 in series expression: (DEFUN MY-SCAN-ALIST (ALIST &OPTIONAL (TEST #'EQL)) (DECLARE (OPTIMIZABLE-SERIES-FUNCTION 2)) (DECLARE (OFF-LINE-PORT 0 1)) (LET* ((ASSOC (CHOOSE-IF #'CONSP (SCAN ALIST))) (KEYS (SERIES::|#M| CAR ASSOC)) (VALS (SERIES::|#M| CDR ASSOC)) (BOOLS (MAP-FN T (UNSEEN-BEFORE :TEST TEST) KEYS))) (COTRUNCATE (CHOOSE BOOLS KEYS) (CHOOSE BOOLS VALS)))) Constraint cycle passes through the off-line output at the start of the = data flow from: (CHOOSE BOOLS KEYS) to: (LET* ((ASSOC (CHOOSE-IF #'CONSP (SCAN ALIST))) (KEYS (SERIES::|#M| CAR = ASSOC)) (VALS (SERIES::|#M| CDR ASSOC)) (BOOLS (MAP-FN T (UNSEEN-BEFORE :TEST TEST) KEYS))) (COTRUNCATE (CHOOSE BOOLS KEYS) (CHOOSE BOOLS VALS))) WARNING: MY-SCAN-ALIST [15]>=20 How can I get this to work? I can't seem to find my way to work on two series in parallel (and I haven't even tackled scan-plist). I have a different version that works, but I'd like to understand the difference or I'll become frustrated: (defun my-scan-alist (alist &optional (test #'eql)) (declare (optimizable-series-function 2)) ;is needed (map-fn '(values t t) (lambda (association) (values (car association) (cdr association))) (choose-if (unseen-before :key #'car :test test) (choose-if #'consp (scan alist))))) My helper function is: (defun unseen-before (&rest hash-table-options &key (key #'identity) &allow-other-keys) ;;Note: using plain alist is faster on small sets (let ((seen (apply #'make-hash-table ;;TODO use my reuse-cons-based remove-keys (loop for (k v) on hash-table-options by #'cddr unless (eq k :key) collect k and collect v)))) (lambda (item &aux (elt (funcall key item))) (unless (gethash elt seen) (setf (gethash elt seen) t))))) BTW, I submitted some bug-reports to series at sourceforge, if you're = curious. http://sourceforge.net/tracker/?group_id=3D3235&atid=3D103235 Using series 2.2.5 on clisp-2.27-win32 on MS-Windows-2k Any help would be appreciated, J=F6rg H=F6hle. ```

Showing results of 50

<< < 1 2 (Page 2 of 2)