لغة ديناميكية

مواقع الإنترنت تنقسم الي مواقع استاتيكية ومواقع ديناميكية الاختلاف الرئيسي بين النوعين يتركز في اللغة المبني بها الموقع فمثلا الموقع المبني بلغة هتمل html هي مواقع استاتيكية أما المبنية بلغة بي اتش بي PHP هي لغات ديناميكية والاختلاف الرئيسي بين النوعين من اللغات هو ان الاستاتيك ثابته المحتوى بمعنى ان الموقع تكون محتوياته ثابته لا تتغير الا بتغيير في الكود المبني به الصفحة الاستاتيكية اما الديناميكية فتتغير وتتأثر بما يجريه عليها المستخدم من عمليات

أشهر لغات برمجة الانترنت الديناميكية ايه اس بي ايه اس بي دوت نت بي اتش بي

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

مثال للكود

The following examples show dynamic features using the language Common Lisp and its Common Lisp Object System (CLOS).


Computation of code at runtime and late binding

The example shows how a function can be modified at runtime from computed source code

; the source code is stored as data in a variable
CL-USER > (defparameter *best-guess-formula* '(lambda (x) (* x x 2.5)))
*BEST-GUESS-FORMULA*

; a function is created from the code and compiled at runtime, the function is available under the name best-guess
CL-USER >  (compile 'best-guess *best-guess-formula*)
#<Function 15 40600152F4>

; the function can be called
CL-USER > (best-guess 10.3)
265.225

; the source code might be improved at runtime
CL-USER > (setf *best-guess-formula* `(lambda (x) ,(list 'sqrt (third *best-guess-formula*))))
(LAMBDA (X) (SQRT (* X X 2.5)))

; a new version of the function is being compiled
CL-USER > (compile 'best-guess *best-guess-formula*)
#<Function 16 406000085C>

; the next call will call the new function, a feature of late binding
CL-USER > (best-guess 10.3)
16.28573

Object runtime alteration

This example shows how an existing instance can be changed to include a new slot when its class changes and that an existing method can be replaced with a new version.

; a person class. The person has a name.
CL-USER > (defclass person () ((name :initarg :name)))
#<STANDARD-CLASS PERSON 4020081FB3>

; a custom printing method for the objects of class person
CL-USER > (defmethod print-object ((p person) stream)
            (print-unreadable-object (p stream :type t)
              (format stream "~a" (slot-value p 'name))))
#<STANDARD-METHOD PRINT-OBJECT NIL (PERSON T) 4020066E5B>

; one example person instance
CL-USER > (setf *person-1* (make-instance 'person :name "Eva Luator"))
#<PERSON Eva Luator>

; the class person gets a second slot. It then has the slots name and age.
CL-USER > (defclass person () ((name :initarg :name) (age :initarg :age :initform :unknown)))
#<STANDARD-CLASS PERSON 4220333E23>

; updating the method to print the object
CL-USER > (defmethod print-object ((p person) stream)
            (print-unreadable-object (p stream :type t)
              (format stream "~a age: ~" (slot-value p 'name) (slot-value p 'age))))
#<STANDARD-METHOD PRINT-OBJECT NIL (PERSON T) 402022ADE3>

; the existing object has now changed, it has an additional slot and a new print method
CL-USER > *person-1*
#<PERSON Eva Luator age: UNKNOWN>

; we can set the new age slot of instance
CL-USER > (setf (slot-value *person-1* 'age) 25)
25

; the object has been updated
CL-USER > *person-1*
#<PERSON Eva Luator age: 25>

Assembling of code at runtime based on the class of instances

In the next example the class person gets a new superclass. The print method gets redefined such that it assembles several methods into the effective method. The effective method gets assembled based on the class of the argument and the at runtime available and applicable methods.

; the class person
CL-USER > (defclass person () ((name :initarg :name)))
#<STANDARD-CLASS PERSON 4220333E23>

; a person just prints its name
CL-USER > (defmethod print-object ((p person) stream)
            (print-unreadable-object (p stream :type t)
              (format stream "~a" (slot-value p 'name))))
#<STANDARD-METHOD PRINT-OBJECT NIL (PERSON T) 40200605AB>

; a person instance
CL-USER > (defparameter *person-1* (make-instance 'person :name "Eva Luator"))
*PERSON-1*

; displaying a person instance
CL-USER > *person-1*
#<PERSON Eva Luator>

; now redefining the print method to be extensible
; the around method creates the context for the print method and it calls the next method
CL-USER > (defmethod print-object :around ((p person) stream)
            (print-unreadable-object (p stream :type t)
              (call-next-method)))
#<STANDARD-METHOD PRINT-OBJECT (:AROUND) (PERSON T) 4020263743>

; the primary method prints the name
CL-USER > (defmethod print-object ((p person) stream)
            (format stream "~a" (slot-value p 'name)))
#<STANDARD-METHOD PRINT-OBJECT NIL (PERSON T) 40202646BB>

; a new class id-mixin provides an id
CL-USER > (defclass id-mixin () ((id :initarg :id)))
#<STANDARD-CLASS ID-MIXIN 422034A7AB>

; the print method just prints the value of the id slot
CL-USER > (defmethod print-object :after ((object id-mixin) stream)
          (format stream " ID: ~a" (slot-value object 'id)))
#<STANDARD-METHOD PRINT-OBJECT (:AFTER) (ID-MIXIN T) 4020278E33>

; now we redefine the class person to include the mixin id-mixin
CL-USER 241 > (defclass person (id-mixin) ((name :initarg :name)))
#<STANDARD-CLASS PERSON 4220333E23>

; the existing instance *person-1* now has a new slot and we set it to 42
CL-USER 242 > (setf (slot-value *person-1* 'id) 42)
42

; displaying the object again. The print-object function now has an effective method, which calls three methods: an around method, the primary method and the after method.
CL-USER 243 > *person-1*
#<PERSON Eva Luator ID: 42>

أمثلة

Popular dynamic programming languages include JavaScript, Python, Ruby, PHP, Lua and Perl. The following are generally considered dynamic languages:

انظر أيضاً

الهامش

  1. ^ Chapter 24. Dynamic language support. Static.springsource.org. Retrieved on 2013-07-17.
  2. ^ <"Archived copy". Archived from the original on 2012-02-13. Retrieved 2014-03-02. {{cite web}}: Unknown parameter |deadurl= ignored (|url-status= suggested) (help)CS1 maint: archived copy as title (link)

للاستزادة

وصلات خارجية

(Many use the term "scripting languages".)