0

Why does secure-hash fail when I use a variable on the second call? Emacs 27.1, 27.2 and 26.3

(setq mytext "test")
(message (secure-hash 'sha256' mytext))
(message (secure-hash 'sha256' "test"))
jsnmtth
  • 13
  • 4

1 Answers1

1

You have an extra quote ' before mytext that prevents evaluation of the mytext variable.

The following works just fine:

(let ((mytext "test"))
  (secure-hash 'sha256 mytext))
==> "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
(secure-hash 'sha256 "test")
==> "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"

PS. If you are new to Lisp and this was not just a typo, you will greatly benefit from reading "An Introduction to Programming in Emacs Lisp". The best way to do it is in Emacs: C-h i m intro TAB RET.

sds
  • 58,617
  • 29
  • 161
  • 278
  • 1
    Thank you so much! That worked out. I'm not exactly new to lisp but I do bumble around in it because I rarely program in it. – jsnmtth Jul 20 '21 at 20:05