DCL Lisp Bad Argument Type Error - arguments

I'm getting this error type:
error: bad argument type: (or stringp symbolp): 1`
Does anybody know why? I think it is in the last if.
(defun C:girth ( / dcl_id gr_ded)
(setq NAMES '("0.032 in" "0.050 in" "0.080 in" "1/8 in" "1/4 in" "16 GA" "18 GA" "20 GA"))
(setq dcl_id (load_dialog "girth.dcl"))
(if (not (new_dialog "girth" dcl_id))
(exit)
)
(start_list "selections")
(mapcar 'add_list NAMES)
(end_list)
(action_tile
"cancel"
"(done_dialog) (setq userclick nil)"
);action_tile
(action_tile
"accept"
(strcat
"(progn
(if (or (= \"selections\" \"0.032 in\") (= \"selections\" \"20 GA\"))
(setq gr_ded 0)
(if (or (= \"selections\" \"0.050 in\") (= \"selections\" \"18 GA\"))
(setq gr_ded 0.0625)
(if (or (= \"selections\" \"0.080 in\") (= \"selections\" \"16 GA\"))
(setq gr_ded 0.125)
(if (= \"selections\" \"1/8 in\")
(setq gr_ded 0.1875)
(if (= \"selections\" \"3/16 in\")
(setq gr_ded 0.3125)
(if (= \"selections\" \"1/4 in\")
(setq gr_ded 0.375)
(setq gr_ded 1)
)
)
)
)
)
)
(alert \"Value: \" (getvar gr_ded)))"
);strcat
);action tile
(start_dialog)
(unload_dialog dcl_id)
(princ)
)
And this is the "new" code (still not working):
gr_ded is now m_deduct and selections is thk.
(defun C:girth ( / dcl_id m_deduct mat_thk)
(setq NAMES '("0.032 in" "0.050 in" "0.080 in" "1/8 in" "1/4 in" "16 GA" "18 GA" "20 GA"))
(setq dcl_id (load_dialog "girth.dcl"))
(if (not (new_dialog "girth" dcl_id))
(exit)
)
(start_list "thk")
(mapcar 'add_list NAMES)
(end_list)
(action_tile
"cancel"
"(done_dialog) (setq userclick nil)"
);action_tile
(action_tile
"accept"
(strcat "(progn (setq mat_thk (get_tile \"thk\"))"
"(done_dialog) (setq UserClick T))"
);strcat
);action_tile
(start_dialog)
(unload_dialog dcl_id)
(if (= UserClick T)
(progn
(cond ((or (= mat_thk "0.032 in") (= mat_thk "20 GA"))
(setq m_deduct 0)
)
((or (= mat_thk "0.050 in") (= mat_thk "18 GA"))
(setq m_deduct 0.0625)
)
((or (= mat_thk "0.080 in") (= mat_thk "16 GA"))
(setq m_deduct 0.125)
)
((= mat_thk "1/8 in")
(setq m_deduct 0.1875)
)
((= mat_thk "3/16 in")
(setq m_deduct 0.3125)
)
((= mat_thk "1/4 in")
(setq m_deduct 0.375)
)
(t (setq m_deduct 1))
);_cond
(alert (strcat "Value: " (rtos m_deduct 2 5)))
);progn
);if userclick
(princ)
);defun
Girth.dcl
girth : dialog {
label = "MyTitle";
initial_focus = "ang1";
: boxed_radio_column {
label = "Calc";
: row {
: popup_list {
label = "Thick:";
key = "thk";
value = "1";
}
: text_part {
label = "Option 1";
}
}
spacer;
: row {
: edit_box {
label = "Angle 1:";
edit_limit = 6;
edit_width = 6;
key = "ang1";
}
: edit_box {
label = "Dim 1:";
edit_limit = 7;
edit_width = 7;
key = "dim1";
}
}
: row {
: edit_box {
label = "Angle 2:";
edit_limit = 6;
edit_width = 6;
key = "ang2";
}
: edit_box {
label = "Dim 2:";
edit_limit = 7;
edit_width = 7;
key = "dim2";
}
}
: row {
: edit_box {
label = "Angle 3:";
edit_limit = 6;
edit_width = 6;
key = "ang3";
}
: edit_box {
label = "Dim 3:";
edit_limit = 7;
edit_width = 7;
key = "dim3";
}
}
: row {
: edit_box {
label = "Angle 4:";
edit_limit = 6;
edit_width = 6;
key = "ang4";
}
: edit_box {
label = "Dim 4:";
edit_limit = 7;
edit_width = 7;
key = "dim4";
}
}
: row {
: edit_box {
label = "Angle 5:";
edit_limit = 6;
edit_width = 6;
key = "ang5";
}
: edit_box {
label = "Dim 5:";
edit_limit = 7;
edit_width = 7;
key = "dim5";
}
}
: row {
: edit_box {
label = "Angle 6:";
edit_limit = 6;
edit_width = 6;
key = "ang6";
}
: edit_box {
label = "Dim 6:";
edit_limit = 7;
edit_width = 7;
key = "dim6";
}
}
: row {
: edit_box {
label = "Angle 7:";
edit_limit = 6;
edit_width = 6;
key = "ang7";
}
: edit_box {
label = "Dim 7:";
edit_limit = 7;
edit_width = 7;
key = "dim7";
}
}
: row {
spacer;
}
}
: row {
key = "det";
: radio_button { label = "A"; value = "1"; }
: radio_button { label = "B"; }
: radio_button { label = "C"; }
}
ok_cancel;
}

I think it is on the line:
(alert \"Value: \" (getvar gr_ded)))
Try to replace with:
(alert (strcat \"Value: \" (rtos gr_ded)))
Not sure about gr_ded. It seems to be a number but why are you calling getvar with it?
And you should use cond instead of nested if.
The strcat in the second argument of action_tile is superfluous.

Related

How are assoc and assq implemented in Scheme?

How are assoc and assq implemented in Scheme?
So what is the intern code of those two procedures?
Ultimately, it doesn't matter how it's implemented as long as it adheres to the behaviour specified in the standard (see section 6.4 of r7rs small).
In Guile, it looks like assq is implemented like this:
SCM_DEFINE (scm_assq, "assq", 2, 0, 0,
(SCM key, SCM alist),
"#deffnx {Scheme Procedure} assv key alist\n"
"#deffnx {Scheme Procedure} assoc key alist\n"
"Fetch the entry in #var{alist} that is associated with #var{key}. To\n"
"decide whether the argument #var{key} matches a particular entry in\n"
"#var{alist}, #code{assq} compares keys with #code{eq?}, #code{assv}\n"
"uses #code{eqv?} and #code{assoc} uses #code{equal?}. If #var{key}\n"
"cannot be found in #var{alist} (according to whichever equality\n"
"predicate is in use), then return #code{#f}. These functions\n"
"return the entire alist entry found (i.e. both the key and the value).")
#define FUNC_NAME s_scm_assq
{
SCM ls = alist;
for(; scm_is_pair (ls); ls = SCM_CDR (ls))
{
SCM tmp = SCM_CAR (ls);
SCM_ASSERT_TYPE (scm_is_pair (tmp), alist, SCM_ARG2, FUNC_NAME,
"association list");
if (scm_is_eq (SCM_CAR (tmp), key))
return tmp;
}
SCM_ASSERT_TYPE (SCM_NULL_OR_NIL_P (ls), alist, SCM_ARG2, FUNC_NAME,
"association list");
return SCM_BOOL_F;
}
#undef FUNC_NAME
Which is the C equivalent of (excluding some type checks):
(define (assq key alist)
(let loop ((ls alist))
(if (pair? ls)
(let ((tmp (car ls)))
(if (eq? (car tmp) key)
tmp
(loop (cdr ls))))
#f)))

Decryption function gives wrong result with special characters

I'm building an encryption/decryption function in VBScript / Classic ASP.
It all works as long as the string to be encrypted/decrypted does not contain special characters.
' str = "Bayern München"
' key = "ab34ehyd67hy6752daskjh"
Function EncryptString(val, key)
valLen = Len(val)
keyLen = Len(key)
keyPos = 1
newVal = ""
revVal = val
For x = 1 To valLen
calc = AscW(Mid(revVal, x, 1)) + AscW(Mid(key, keyPos, 1))
'Response.Write ":" & AscW(Mid(revVal, x, 1)) & " + " & AscW(Mid(key, keyPos, 1)) & " = " & calc & "<br />"
newVal = newVal & Hex(calc)
keyPos = keyPos + 1
If keyPos > keyLen Then keyPos = 1
Next
EncryptString = newVal
End Function
Function DecryptString(val, key)
' The workaround - start
For i = 160 To 255
val = Replace(val, Chr(i), "&#" & i & ";")
Next
' The workaround - end
valLen = Len(val)
keyLen = Len(key)
keyPos = 1
newVal = ""
revVal = val
chrVal = ""
' I suspect this to be the error
For y = 1 To valLen Step 2
chrVal = chrVal & ChrW("&h" & Mid(revVal, y, 2))
Next
For x = 1 To Len(chrVal)
calc = AscW(Mid(chrVal, x, 1)) - AscW(Mid(key, keyPos, 1))
'Response.Write "::" & AscW(Mid(chrVal, x, 1)) & " - " & AscW(Mid(key, keyPos, 1)) & " = " & calc & "<br />"
newVal = newVal & ChrW(calc)
keyPos = keyPos + 1
If keyPos > keyLen Then keyPos = 1
Next
DecryptString = newVal
End Function
If I do an encryption of the string "Bayern München" and afterwards call the DecryptString function on the encrypted string, it returns Bayern M?À?vU?.
If I output the data (the Response.Write's in the example), the decryption function returns a negative number for the character ü, so I'm doing something wrong - but what?
The system encoding is Windows-1252.
UPDATE:
I did this workaround in the DecryptString function. I'm not sure if it covers all possible problems, but from my testing so far it does:
For i = 160 To 255
val = Replace(val, Chr(i), "&#" & i & ";")
Next
Don't know if you still need to fix it, but all above is because hex() returns a string longer than 2 for any decimal over 255:
(255)10 = (FF)16
(256)10 = (100)16
i.e. when original string + salt is over 255(10)
("ü" 252) + ("6" 54) = 252+54 = 306(10)=132(16) (3 characters long)
then "For y=1 To valLen Step 2" will take only "13" of "132" which will result to improper decryption.
Depends on the need, it can be "fixed", for example, by checking if encrypted code is over 255 and when true, do not add salt:
Function EncryptString(val, key)
...
'newVal = newVal & Hex(calc) <-- replace this by following code
if calc > 255 then
newVal = newVal & "01" & Hex(Asc(Mid(revVal, x, 1))) ' no salt
else
newVal = newVal & Hex(calc)
end if
where "01" is just a "signal" character that tells that the next char will be without salt.
Respectively,
Function DecryptString(val, key)
...
'calc = Asc(Mid(chrVal, x, 1)) - Asc(Mid(key, keyPos, 1))
if Asc(Mid(chrVal, x, 1))=1 then 'determine "signal"
ignorenext = true 'flag that next char has no salt
else
if ignorenext then
calc = Asc(Mid(chrVal, x, 1)) 'no salt
ignorenext = false
else
calc = Asc(Mid(chrVal, x, 1)) - Asc(Mid(key, keyPos, 1))
end if
newVal = newVal & Chr(calc)
keyPos = keyPos + 1
If keyPos > keyLen Then keyPos = 1
end if
Note, for Windows-1252 no need to use AscW()/ChrW() which are unicode specific.
Another approach will be to replace hexadecimal by something more "stable" i.e. base32. Taking sample code from Classic ASP/VBScript implementation of Crockford's Base32 Encoding your code can look like
Function EncryptString(val, key)
valLen = Len(val)
keyLen = Len(key)
keyPos = 1
newVal = ""
revVal = val
For x = 1 To valLen
calc = Asc(Mid(revVal, x, 1)) + Asc(Mid(key, keyPos, 1))
newVal = newVal & ToBase32(calc)
keyPos = keyPos + 1
If keyPos > keyLen Then keyPos = 1
Next
EncryptString = ucase(newVal)
End Function
Function DecryptString(val, key)
valLen = Len(val)
keyLen = Len(key)
keyPos = 1
newVal = ""
revVal = val
chrVal = ""
For y = 1 To valLen Step 2
chrVal = chrVal & fromBase32(Mid(revVal, y, 2))
calc = fromBase32(Mid(revVal, y, 2)) - Asc(Mid(key, keyPos, 1))
newVal = newVal & Chr(calc)
keyPos = keyPos + 1
If keyPos > keyLen Then keyPos = 1
Next
DecryptString = newVal
End Function

Jess matching rule does not fire

I am having difficulties in defining matching rules.
(defrule set-current
?desAct <- (Actuator (name 0) (StrokeLength ?sl) (Force ?f)
(nominalCurrent ?c3))
(test (eq ?c3 0)) ; I have defined this to change only if value is not
; set yet
?act <- (Actuator (inputVoltage ?v1) ; actuator that has matching slots
(StrokeLength ?sl1)
(nominalCurrent ?c1))
(test (eq ?sl1 ?sl)) ; for same stroke length I want to modify
; nominalCurrent of ?desAct
=>
(modify ?desAct (nominalCurrent ?c1))
)
?desAct represent the fact which slots values I want to change according to other existing facts based on some criteria.
I am not sure why this rule doesn't fire for following facts:
f-4 (MAIN::Actuator (name 4) (inputVoltage 12) (Force 17) (StrokeLength 10) (length 62) (width 18) (height 15.1) (motorType DC) (speedAtNomLoad 25) (weight 28) (nominalCurrent 0.46) (highTemp 50) (lowTemp -10) (price 90) (dutyCycle 20))
f-9 (MAIN::Actuator (name 0) (inputVoltage 12) (Force 17) (StrokeLength 10) (length 10) (width 10) (height 10) (motorType DC) (speedAtNomLoad 0) (weight 0) (nominalCurrent 0) (highTemp 0) (lowTemp 0) (price 0) (dutyCycle 0))
I am expecting that Actuator with name 0 with this rule has nominalCurrent same as f-4, but rule doesn't fire.
The rule does fire but more than once. If you have facts of the same template, make sure to avoid multiple matches of 1 or 2 facts.
(defrule set-current
?act1 <- (Actuator (name ?n1)
(inputVoltage ?v1)
(StrokeLength ?sl1)
(nominalCurrent ?c1&0))
?act2 <- (Actuator (name ?n2&~?n1) ; avoid redundant matches
(inputVoltage ?v1) ; same input voltage
(StrokeLength ?sl1) ; same stroke length
(nominalCurrent ?c2)) ; bind current
=>
(printout t "modify actuator " ?n1 " current=" ?c2 crlf)
(modify ?act1 (nominalCurrent ?c2))
)
The constraint (name ?n2&~?n1) forces matches to occur between Actuators with different name values. Reusing a bound variable forces a match with a slot of that value.
Don't use test. Be more consistent with the names for binding variables.

Search record by name and display in data grid in VB and Access

I am a TyBCA student I am creating a window application using VB as a front end and MS Access as back end. As I am creating a Gym management system Software in it I cannot figure out what's the problem in my search code.
According to it should be like when I click on the search Btn a message box /dialog box should appear asking "Enter the Name to Search" and the result should be displayed on the Data Grid named "MS1" and "MS".
MS1.Visible = False
MS.Visible = True
Command4.Visible = False
Command6.Visible = True
id = InputBox("enter the id")
rr.Open "select * from tblMembers where Member_id=" & id, cn, adOpenDynamic, adLockOptimistic
If Not (rr.EOF) Then
MS.Cols = 20
MS1.TextMatrix(0, 0) = "Member_id"
MS1.TextMatrix(0, 1) = "First_Name"
MS1.TextMatrix(0, 2) = "Last_Name"
MS1.TextMatrix(0, 3) = "Gender"
MS1.TextMatrix(0, 4) = "Membership"
MS1.TextMatrix(0, 5) = "Address"
MS1.TextMatrix(0, 6) = "Zip_Code"
MS1.TextMatrix(0, 7) = "Date_Of_Birth"
MS1.TextMatrix(0, 8) = "Mobile_No"
MS1.TextMatrix(0, 9) = "Medical_History"
MS1.TextMatrix(0, 10) = "Pay_Due_Date"
MS1.TextMatrix(0, 11) = "Amount"
MS1.TextMatrix(0, 12) = "Installed_amt"
MS1.TextMatrix(0, 13) = "Balance"
MS1.TextMatrix(0, 14) = "Profile"
rr.MoveFirst
r = 1
Do While Not rr.EOF
MS1.Rows = MS1.Rows + 1
MS1.TextMatrix(r, 0) = rr.Fields(0)
MS1.TextMatrix(r, 1) = rr.Fields(1)
MS1.TextMatrix(r, 2) = rr.Fields(2)
MS1.TextMatrix(r, 3) = rr.Fields(3)
MS1.TextMatrix(r, 4) = rr.Fields(4)
MS1.TextMatrix(r, 5) = rr.Fields(5)
MS1.TextMatrix(r, 6) = rr.Fields(6)
MS1.TextMatrix(r, 7) = rr.Fields(7)
MS1.TextMatrix(r, 8) = rr.Fields(8)
MS1.TextMatrix(r, 9) = rr.Fields(9)
MS1.TextMatrix(r, 10) = rr.Fields(10)
MS1.TextMatrix(r, 11) = rr.Fields(11)
MS1.TextMatrix(r, 12) = rr.Fields(12)
MS1.TextMatrix(r, 13) = rr.Fields(13)
rr.MoveNext
r = r + 1
Loop
rr.Close
It's worth nothing, but in your code you only display MS (first two lines), then only fill MS1.

Which variable is set by `search-forward` in elisp?

In elisp to replace an occurrence of a string in a buffer I would do
(search-forward "aaa" nil 't)
(replace-match "bbb")
If between the search and the replace I modify the buffer, the following seems to happen:
(match-end 1) <- (min (point-max) (match-end 1))
(match-beginning 1) <- (min (match-beginning 1) (match-end 1))
Moreover if (match-end 1)==(match-beginning 1) replace-match calls insert at (match-end 1) (both of which gets updated to point to the end of the inserted string) whereas if (match-end 1)>(match-beginning 1) replace-match updates the string between (match-beginning 1) and (match-end 1) (and they get updated to point to the beginning and end of the inserted string)
So the second question is why the different behaviours?

Resources