misc.scm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ;;; GNU Mes --- Maxwell Equations of Software
  2. ;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Mes.
  5. ;;;
  6. ;;; GNU Mes is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Mes is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (mes misc)
  19. #:use-module (srfi srfi-1)
  20. #:export (%scheme
  21. disjoin
  22. guile?
  23. mes?
  24. pk
  25. pke
  26. warn
  27. stderr
  28. string-substitute))
  29. (cond-expand
  30. (mes
  31. (define %scheme "mes"))
  32. (guile
  33. (define %scheme "guile")))
  34. (define guile? (equal? %scheme "guile"))
  35. (define mes? (equal? %scheme "mes"))
  36. (define (logf port string . rest)
  37. (apply format (cons* port string rest))
  38. (force-output port)
  39. #t)
  40. (define (stderr string . rest)
  41. (apply logf (cons* (current-error-port) string rest)))
  42. (define (pk . stuff)
  43. (newline)
  44. (display ";;; ")
  45. (write stuff)
  46. (newline)
  47. (car (last-pair stuff)))
  48. (define (pke . stuff)
  49. (display "\n" (current-error-port))
  50. (newline (current-error-port))
  51. (display ";;; " (current-error-port))
  52. (write stuff (current-error-port))
  53. (display "\n" (current-error-port))
  54. (car (last-pair stuff)))
  55. (define warn pke)
  56. (define (disjoin . predicates)
  57. (lambda (. arguments)
  58. (any (lambda (o) (apply o arguments)) predicates)))
  59. (define (string-substitute string find replace)
  60. (let ((index (string-contains string find)))
  61. (if (not index) string
  62. (string-append
  63. (string-take string index)
  64. replace
  65. (string-substitute
  66. (string-drop string (+ index (string-length find)))
  67. find replace)))))