[personal profile] dmitry_vk
Просто некоторый надоедливый факт.
Сравним:
public class TextTag
{
  private int begin;
  public int Begin
  {
    get { return begin; }
    set { begin = value; }
  }

  private int length;
  public int Length
  {
    get { return length; }
    set { length = value; }
  }

  private Dictionary<string,object> attributes = new Dictionary<string,object>();
  public object this[string attributeName]
  {
    get { return attributes[attributeName]; }
    set
    {
      if (attribues.ContainsKey(attributeName))
        attributes[attributeName] = value;
      else
        attributs.Add(attributeName,value);
    }
  }

  public TextTag(int begin, int length)
  {
    this.begin = begin;
    this.length = length;
  }
}

new TextTag(0,15);

vs
(defclass tag ()
  ((begin
    :accessor tag-begin
    :type integer
    :initarg :begin)
   (length
    :accessor tag-length
    :type integer
    :initarg :length)
   (attributes
    :type hash-table
    :initform (make-hash-table))))

(defun attribute-of (tag attribute-name)
  (gethash attribute-name (slot-value tag 'attributes)))

(defun set-attribute-of (tag attribute-name attribute-value)
  (setf (gethash attribute-name (slot-value tag 'attributes)) attribute-value))

(defsetf attribute-of set-attribute-of)

(make-instance 'tag :begin 0 :length 15)


Когда пишу на c#, чувствую себя очень неуютно… Все эти лишние вещи, которые надо сначала писать, а потом читать, которые путаются, лезут в глаза, вызывают ошибки компиляции… В любом случае, syntactic sugar matters, и лисп самый «сахарный» в этом отношении.
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

dmitry_vk

April 2023

S M T W T F S
      1
234567 8
9101112131415
16171819202122
23242526272829
30      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Apr. 6th, 2026 07:13 am
Powered by Dreamwidth Studios