Giter Site home page Giter Site logo

Comments (9)

attila-lendvai avatar attila-lendvai commented on August 17, 2024

FTR, the current (apparently failed?) attempt at fixing it was discussed in: #66

from fibers.

mwette avatar mwette commented on August 17, 2024

What about replacing guile-3 case of bit-count with (module-variable (resolve-module '(guile)) 'bit-count)?

from fibers.

attila-lendvai avatar attila-lendvai commented on August 17, 2024

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.

mwette avatar mwette commented on August 17, 2024

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.

mwette avatar mwette commented on August 17, 2024

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.

attila-lendvai avatar attila-lendvai commented on August 17, 2024

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:

  1. lobby for changing cond-expand in guile
  2. lobby for adding cond-expand* to guile
  3. or open a PR for fibers that adds it as a local utility.

from fibers.

attila-lendvai avatar attila-lendvai commented on August 17, 2024

or this should also work:

(cond-expand*
 ((not (defined? 'bitvector-count))
  (define (bitvector-count v)
    (bit-count #t v)))
 (else
  (values)))

from fibers.

civodul avatar civodul commented on August 17, 2024

@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.

attila-lendvai avatar attila-lendvai commented on August 17, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.