@kyanny's blog

My thoughts, my life. Views/opinions are my own.


Emacs Lisp Intro で let のページを読んだ。

   Another way to think about `let' is that it is like a `setq' that is
temporary and local.  The values set by `let' are automatically undone
when the `let' is finished.  The setting only affects expressions that
are inside the bounds of the `let' expression.  In computer science
jargon, we would say "the binding of a symbol is visible only in
functions called in the `let' form; in Emacs Lisp, scoping is dynamic,
not lexical."


Emacs Lisp

(defun foo ()
  (message "value of `foo' is %s" foo))
;=> foo

    ((foo "FOO"))
;=> "value of `foo' is FOO"

Perl にただ翻訳すると、こうか?

#!/usr/bin/env perl
use strict;
use warnings;

sub foo {
    printf "value of `foo' is %s", $foo;

    my $foo = "FOO";
# $ perl foo.pl 
# Global symbol "$foo" requires explicit package name at foo.pl line 6.
# Execution of foo.pl aborted due to compilation errors.