Language:EN
Pages: 2
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
ematter edition copyright oreilly associates

Ematter edition copyright oreilly associates

• There is no safe way to access a slot of the structure. Any typographical error in either part of the variable name yields the wrong value (or no value) with no warning from make.

But the remote-file function hints at a more comprehensive solution. Suppose we implement structure instances using computed variables. Early Lisp object systems (and even some today) used similar techniques. A structure, say file-info, can have instances represented by a symbolic name, such as file_info_1.

Elements of a file-info can be accessed using Lisp-like getters and setters:

path := $(call get-value,before_foo,path)
$(call set-value,before_foo,path,/usr/tmp/bar)

$(call defstruct,file-info, \
$(call defslot,path,), \
$(call defslot,type,unix), \
$(call defslot,host,oscar))

Here, the first argument to the defstruct function is the structure name, followed by a list of defslot calls. Each defslot contains a single (name, default value) pair.

Data Structures | 253

Example B-1. Structure definition in make (continued)

# all_structs - a list of the defined structure names
all_structs :=

# $(call new, struct_name)
define new
$(strip \ $(if $(filter $1,$(all_structs)),, \ $(error new on unknown struct '$(strip $1)')) \ $(eval instance := $1@$(next-id)) \ $(eval all_instances += $(instance)) \ $(foreach v, $($(strip $1)_def_slotnames), \ $(eval $(instance)_$v := $($(strip $1)_def_$v_default))) \ $(instance))
endef

# $(call delete, variable)
define delete
$(strip \ $(if $(filter $($(strip $1)),$(all_instances)),, \ $(error Invalid instance '$($(strip $1))')) \ $(eval all_instances := $(filter-out $($(strip $1)),$(all_instances))) \ $(foreach v, $($(strip $1)_def_slotnames), \ $(eval $(instance)_$v := )))
endef

|

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Pedro Henrique Moura

PageId: ELIED93481