Comments (9)
FTR, the current (apparently failed?) attempt at fixing it was discussed in: #66
from fibers.
What about replacing guile-3 case of bit-count
with (module-variable (resolve-module '(guile)) 'bit-count)
?
from fibers.
unfortunately guile is too smart:
x.scm:
#!/usr/bin/env -S guile --no-auto-compile -e 'main' -s
!#
(define (main cli-args)
;;(pk (bit-count #t #*101))
(pk ((variable-ref (module-variable (resolve-module '(guile)) 'bit-count)) #t #*101))
)
$ export GUILE_WARN_DEPRECATED=detailed
$ /tmp/x.scm
bit-count is deprecated. Use bitvector-count, or a loop over array-ref if array support is needed.
scm_bitvector_length is deprecated. Use scm_c_bitvector_length instead.
;;; (2)
from fibers.
This code in bitv.scm
(define bitvector-count*
(if (defined? 'bitvector-count)
bitvector-count
(lambda (v)
((module-ref (resolve-module '(guile)) 'bit-count) #t v))))
(display (version)) (newline)
(display (bitvector-count* #*101)) (newline)
gives
$ GUILE_WARN_DEPRECATED_DETAILED=detailed guile bitv.scm
3.0.8
2
And on freshly built 3.0.2:
$ GUILE_WARN_DEPRECATED_DETAILED=detailed guile bitv.scm
3.0.2
2
EDIT: There was a bug in the proposed sol'n above: module-variable
should be module-ref
. [fixed]
from fibers.
The above might be slower, but only for 3.0, to 3.0.2.
scheme@(guile-user)> ,optimize (lambda (v) ((module-ref (resolve-module '(guile)) 'bit-count) #t v))
$1 = (lambda (v)
((module-ref (resolve-module '(guile)) 'bit-count)
#t
v))
from fibers.
FTR, this in a file:
(pk ((module-ref (resolve-module '(guile)) 'bit-count) #t #*101))
still leads to this:
$ guile --version
guile (GNU Guile) 3.0.9
$ GUILE_WARN_DEPRECATED=detailed guile /tmp/x.scm
bit-count is deprecated. Use bitvector-count, or a loop over array-ref if array support is needed.
scm_bitvector_length is deprecated. Use scm_c_bitvector_length instead.
;;; (2)
$
what we need here is a cond-expand*
that dispatches at macroexpand-time:
(define-syntax cond-expand*
(lambda (x)
(define (condition-matches? condition)
(syntax-case condition (and or not)
((and c ...)
(and-map condition-matches? #'(c ...)))
((or c ...)
(or-map condition-matches? #'(c ...)))
((not c)
(if (condition-matches? #'c) #f #t))
(c
(eval #'c (current-module)))))
(define (match clauses alternate)
(syntax-case clauses ()
(((condition form ...) . rest)
(if (condition-matches? #'condition)
#'(begin form ...)
(match #'rest alternate)))
(() (alternate))))
(syntax-case x (else)
((_ clause ... (else form ...))
(match #'(clause ...)
(lambda ()
#'(begin form ...))))
((_ clause ...)
(match #'(clause ...)
(lambda ()
(syntax-violation 'cond-expand* "unfulfilled cond-expand*" x)))))))
(define bitvector-count*
(cond-expand*
((defined? 'bitvector-count)
bitvector-count)
(else
(lambda (v) (bit-count #t v)))))
(pk (bitvector-count* #*101))
i'm just not sure where to add it:
- lobby for changing
cond-expand
in guile - lobby for adding
cond-expand*
to guile - or open a PR for fibers that adds it as a local utility.
from fibers.
or this should also work:
(cond-expand*
((not (defined? 'bitvector-count))
(define (bitvector-count v)
(bit-count #t v)))
(else
(values)))
from fibers.
@attila-lendvai Or maybe just something like:
(define bitvector-count
(or (and=> (module-variable the-scm-module 'bitvector-count) variable-ref)
(lambda (v) (bit-count #t v))))
from fibers.
@civodul strangely enough that works indeed!
i thought the deprecation warning trap is installed at reading the variable, but your solution would trigger that, too. maybe the trap is ignored at toplevel-form-evaluation/compilation-time?
either way, thanks for pointing out a much simpler solution!
from fibers.
Related Issues (20)
- Possibly wrong usage of atomic-box-set!
- Lots of unmerged pull reqs!? HOT 4
- Unknown meta command: fibers HOT 2
- In procedure pipe: Too many open files HOT 6
- Infinite loops on uncaught exceptions HOT 5
- Guix build guile-fibers test fails: Too many heap sections. HOT 2
- epoll instance is dead HOT 6
- fibers does not build without epoll HOT 4
- Memory leak on context switches HOT 9
- fibers.scm uses deprecated bitvector-set! HOT 7
- README.md doesn't document dependencies
- fibers depends on gnulib HOT 1
- configure.ac has two operating systems hard-coded, posix-clocks-foo.scm related? HOT 4
- `race-until` test runs forever (1.2.0 + affinity patch, NetBSD 9 amd64) HOT 1
- Cannot print backtraces within a fiber HOT 13
- [doc] clarify the use of dynamic-wind, probably in the Barriers chapter HOT 1
- Fibers wait can forever on a file descriptor once it has been closed HOT 1
- 'get-message' continuation fired more than once? HOT 13
- On GNU/Hurd, 'time_units_per_microsec' is zero HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fibers.