Sigil for Function Parameter Names

,

new crotchet: all function parameter names should start with φ.

Example in emacs lisp:

(defun xah-fix-ellipsis (φstring &optional φfrom φto)
  "Change “...” to “…”.

When called interactively, work on current text block or text selection. (a “text block” is text between empty lines)

When called in lisp code, if φstring is non-nil, returns a changed string.  If φstring nil, change the text in the region between positions φfrom φto."
  (interactive
   (if (region-active-p)
       (list nil (region-beginning) (region-end))
     (let ((bds (get-selection-or-unit 'block)) )
       (list nil (elt bds 1) (elt bds 2)) ) ) )

  (let (workOnStringP inputStr outputStr)
    (setq workOnStringP (if φstring t nil))
    (setq inputStr (if workOnStringP φstring (buffer-substring-no-properties φfrom φto)))
    (setq outputStr (replace-regexp-in-string "\\.\\.\\." "…" inputStr))

    (if workOnStringP
        outputStr
      (save-excursion
        (delete-region φfrom φto)
        (goto-char φfrom)
        (insert outputStr) )) )
  )

〔☛ Xah Emacs Lisp Tutorial

Example in JavaScript:

function draw_rect (φx_coord, φy_coord, φwidth, φheight) {
    // returns a svg rect element
    var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
    rect.setAttribute("x", φx_coord.toString());
    rect.setAttribute("y", φy_coord.toString());
    rect.setAttribute("width", φwidth.toString());
    rect.setAttribute("height", φheight.toString());
    return rect;
}

〔☛ JavaScript Tutorial by Example

this is experimental. I'm going to see how it goes.

why do you want to do this?

I want to be able to distinguish function parameters easily from local variables. (and, ideally, also easily distinguish GLOBAL variables. And built-in vs user-defined. And, wish every identifier is unique.) 〔☛ Programing Style: Variable Naming: English Words Considered Harmful

note, the choice of the character takes some consideration. You want a char that is:

note: sigil is mostly popularly associated with perl. 〔☛ Perl Tutorial by Example〕 But it's also used in PHP〔☛ PHP Tutorial by Example〕and Ruby〔☛ Ruby Tutorial by Example〕, as these 2 languages directly borrowed it from Perl. (perl borrowed it from unix shell.)

The idea of sigil is however quite widespread. Many languages have special chars as starting or ending variable names to indicate special purpose, though, mostly as a convention only, not part of the language machinery. For example, Mathematica variables starting with $ are pre-defined global special variables. (see: http://reference.wolfram.com/mathematica/tutorial/GlobalSystemInformation.html), since 1988.

the name sigil is coined by Philip Gwyn in 1999 to refer to perl's sigil, according to Wikipedia: Sigil (computer programming)

blog comments powered by Disqus