I have a function that returns different functions depending on the value of an integer i. Some values of this integer return the same function but I am unsure how to implement this. The function was formerly:
function myfunc(x,i::Int)
if i == i_A
return funcA(x)
elseif i == i_B
return funcB(x)
elseif i == i_C
return funcB(x)
elseif i == i_D
return funcB(x)
else
throw(DomainError(i, "Error"))
end
which I have unsuccessfully tried to abbreviate to:
function myfunc(x,i::Int)
if i == i_A
return funcA(x)
elseif i == i_B || i_C || i_D
return funcB(x)
else
throw(DomainError(i, "Error"))
end
What is the proper syntax for multiple 'or' in a julia if loop?
As stated in the comments, you can use:
function myfunc(x,i::Int)
if i == i_A
return funcA(x)
elseif i == i_B || i == i_C || i == i_D
return funcB(x)
else
throw(DomainError(i, "Error"))
end
end
Or you can use the keyword in like this:
function myfunc(x,i::Int)
if i == i_A
return funcA(x)
elseif i in [i_B, i_C, i_D]
return funcB(x)
else
throw(DomainError(i, "Error"))
end
end
I personnaly prefer the latter because it is easier to read, and easier to edit.
You can even change your test dynamically by making the array [i_B, i_C, i_D] a variable and change its content dynamically.
Related
Hi i got question for the entity query. Please see my code
var list = from table in db.USER_BETTINGS
where table.UserID == UserId
&& table.UserID !="admin"
//&& table.WinningAfterRebate != 0m
&& table.BettingTransactionTime >= fromDate &&
table.BettingTransactionTime <= toDAte
//&& table.WinningAfterRebate !=0m
// orderby table.BettingTransactionNumber descending//table.BettingNumber descending//, table.BettingTransactionTime descending//
select table;
if (loteryNumber != 0)
{
list= list.Where(x => x.LotteryNumber == loteryNumber);
}
if (gameNum != 0)
{
list= list.Where(x => x.GameNumber == gameNum);
}
if (periodDate != "")
{
list= list.Where(x => x.PeriodDate == periodDate);
}
if (close.Equals("Y"))
{
list= list.Where(w => w.WinningAfterRebate != 0m);
}
else
{
list= list.Where(x => x.WinningAfterRebate == 0);
}
But the list not filtering , It return all record? Anyone got face this problem before?
You need some makeover in this code. You have unnecessarily used so many if condition, we need to get rid of that first. Change your query with the following.
var list =( from table in db.USER_BETTINGS
where table.UserID == UserId
&& table.UserID !="admin"
&& table.BettingTransactionTime >= fromDate
&& table.BettingTransactionTime <= toDAte
&& table.LotteryNumber == (loteryNumber != 0 ? loteryNumber : table.LotteryNumber)
&& table.GameNumber == (gameNum != 0 ? gameNum : table.GameNumber)
&& table.PeriodDate == (periodDate != string.Empty ? periodDate : table.PeriodDate )
&& (close.Equals("Y") ? table.WinningAfterRebate != 0 : table.WinningAfterRebate == 0)
).ToList();
I have this clobagg function:
create or replace type clobagg_type as object(
text clob,
static function ODCIAggregateInitialize(sctx in out clobagg_type
) return number,
member function ODCIAggregateIterate(self in out clobagg_type,
value in clob
) return number,
member function ODCIAggregateTerminate(self in clobagg_type,
returnvalue out clob,
flags in number
) return number,
member function ODCIAggregateMerge(self in out clobagg_type,
ctx2 in clobagg_type
) return number
);
/
create or replace type body clobagg_type is
static function ODCIAggregateInitialize(sctx in out clobagg_type
) return number is
begin
sctx := clobagg_type(null);
return ODCIConst.Success;
end;
member function ODCIAggregateIterate(self in out clobagg_type,
value in clob
) return number is
begin
self.text := self.text || value;
return ODCIConst.Success;
end;
member function ODCIAggregateTerminate(self in clobagg_type,
returnvalue out clob,
flags in number
) return number is
begin
returnValue := self.text;
return ODCIConst.Success;
end;
member function ODCIAggregateMerge(self in out clobagg_type,
ctx2 in clobagg_type
)return number is
begin
self.text := self.text || ctx2.text;
return ODCIConst.Success;
end;
end;
/
create or replace function clobagg(input clob) return clob
deterministic
parallel_enable
aggregate using clobagg_type;
/
But the problem is that I get data not in the right order. Can you help me and tell me how do achieve right order? I need clobagg function because listagg and other can return 4000 bytes and in my case it is not enough.
Here is the query:
CREATE TABLE GO_PRJ_SACHV7.TEST_STEPS1 (
test_case_id NUMBER(9,0),
activity CLOB
);
INSERT INTO GO_PRJ_SACHV7.TEST_STEPS(test_case_id, activity)
select test_case_id, clobagg(activity1)
from (
select
testschrit.testfall_id as test_case_id,
TESTSCHRITT_NR,
CHR(10) || 'h2.' || TESTSCHRITT_NR || ' ' ||
CAST(TESTSCHRITT_BEZEICHNUNG AS varchar(800)) || CHR(10) ||
CAST(TESTSCHRITT_BESCHREIBUNG AS varchar(800)) || CHR(10) ||
CAST(testschrit.TESTSCHRITT_BESCHREIBUNG AS varchar(800)) ||
'||AKTIVITÄT_NR' || '||AKTIVITÄT_KÜRZEL' || '||AKTIVITÄT_BESCHREIBUNG' ||
'||AKTIVITÄT_ERWARTETES_ERGEBNIS||' || CHR(10) ||
clobagg(
' |' || aktiv.AKTIVITÄT_NR || ' |' || aktiv.AKTIVITÄT_KÜRZEL || ' |' ||
aktiv.AKTIVITÄT_BESCHREIBUNG || ' |' ||
aktiv.AKTIVITÄT_ERWARTETES_ERGEBNIS || ' |' || CHR(10)
) as activity1
FROM
GO_PRJ_SACHV7.TESTFALLBESCHREIBUNG tfb,
GO_PRJ_SACHV7.TESTSCHRITTE testschrit,
GO_PRJ_SACHV7.AKTIVITÄTEN aktiv
WHERE testschrit.testfall_id = tfb.testfall_id(+)
AND testschrit.TESTSCHRITT_ID=aktiv.TESTSCHRITT_ID (+)
Group by
testschrit.testfall_id,
testschrit.testschritt_id,
testschrit.TESTSCHRITT_NR,
CAST(TESTSCHRITT_BEZEICHNUNG AS varchar(600)),
CAST(TESTSCHRITT_BESCHREIBUNG AS varchar(600))
order by testschrit.testfall_id, TESTSCHRITT_NR
)
group by test_case_id;
I try to add 'activity' column to the table in the right order. For this moment I can add this to the table but with random order. When I am trying order data by aktiv.AKTIVITÄT_NR I also have to add this field to my group by and this destroy my grouping.
You're missing an order by for the inner aggregate. You need to order before aggregating. You do that before the outer aggregate but not the inner one.
on the select event i have the starting date and the ending date of the event as parameter.
also i have a list of times
and i want to see if any of the items of my list is between of the event start and endtime
the 3 objects are in Date Format
how can i compare the 3 Times of the Dates to see if if its true????
select: function (start, end, allDay) {
var defaultTemplate = undefined;
$.each(jsonTimeTemplates, function(){
templateStartTime = $.fullCalendar.parseDate(this.Start);
templateEndTime = $.fullCalendar.parseDate(this.End);
if(( templateStartTime.getTime() >= start.getTime()) && ( templateStartTime.getTime() <= end.getTime())){
defaultTemplate = this;
}
});
},
in this case jsonTimeTemplates is my list of objects but when i debug with firebug the if sentence never applies.
here i have an screenshot of my debugging where i have
8:00>=8:00 && 8:00 <= 8:15
i hope the dates arent making the problem here.
function compareDates(dateFrom, dateTo){
if ( Date.parse( dateTo ) < Date.parse( dateFrom ) )
return true;
return false;
}
This function returns true if dateTo is smaller than dateFrom. You can use this function to reach your goal.
Function call:
var startDateStr = $.fullCalendar.formatDate(start, 'MM/dd/yyyy hh:mm tt');
var endDateStr = $.fullCalendar.formatDate(end, 'MM/dd/yyyy hh:mm tt');
compareDates(startDateStr, endDateStr);
in the mean time i used the functions gethours and getminutes to do the comparisons. but i hope theres a better way to do this
if( ( templateStartTime.getHours() >= start.getHours() ) && ( templateStartTime.getHours() <= end.getHours() ) &&
(templateStartTime.getMinutes() >= start.getMinutes() ) && ( templateStartTime.getMinutes() <= end.getMinutes() ))
{
defaultTemplate = this;
}
Hey guys, just wondering why ain't my menu working, I've been coding it for like 8 hours now and just can't figure out what's wrong.
Menu = {
label = "Mahin Menu",
current = current or true,
open = open or true,
subMenus = {}
}
function Menu.newSubMenu()
return {
setup = Menu.setup,
print = Menu.print,
toggleOpen = Menu.toggleOpen,
getCurrentMenu = Menu.getCurrentMenu,
getLastMenu = Menu.getLastMenu,
getNextMenu = Menu.getNextMenu,
getPrevMenu = Menu.getPrevMenu
}
end
function Menu:setup(m_parent, m_label, m_action)
self.parent = m_parent
self.label = m_label
self.action = m_action
self.subMenus = {}
self.current = false
self.open = false
table.insert(m_parent.subMenus, self)
end
function Menu:print(indent)
io.write(string.rep(" ", indent))
if #self.subMenus>0 then
if self.open == true then
io.write("[-]")
else
io.write("[+]")
end
else
io.write(" ")
end
if self.current == true then
io.write("<" .. self.label .. ">")
else
io.write(" " .. self.label)
end
io.write("\n")
if #self.subMenus>0 and self.open == true then
for i=1,#self.subMenus do
self.subMenus[i]:print(indent+1)
end
end
end
function Menu:toggleOpen()
if self.open == true then
self.open = false
else
self.open = true
end
end
function Menu:getCurrentMenu()
if self.current == true then
return self
else
for k=1,#self.subMenus do
local v = self.subMenus[k]:getCurrentMenu()
if v ~= nil then
return v
end
end
end
end
function Menu:getLastMenu()
if self.open == true and #self.subMenus > 0 then
return self.subMenus[#self.subMenus]:getLastMenu()
else
return self
end
end
function Menu:getNextMenu(bool)
bool = bool or false
if bool == false then
if #self.subMenus > 0 and self.open == true then
return self.subMenus[1]
end
end
if self.parent then
if self.parent.subMenus[#self.parent.subMenus] == self then
self.parent:getNextMenu(true)
else
for i=1,#self.parent.subMenus do
if self.parent.subMenus[i] == self then
print(self.parent.subMenus[i+1].label)
return self.parent.subMenus[i+1]
end
end
end
else
return self
end
end
function Menu:getPrevMenu()
if self.parent then
for k=1,#self.parent.subMenus do
if self.parent.subMenus[k] == self then
if k == 1 then
return self.parent
elseif #self.parent.subMenus[k-1].subMenus > 0 and self.parent.subMenus[k-1].open == true then
local x = self.parent.subMenus[k-1]
while #x.subMenus > 0 and x.open == true do
x = x.subMenus[#x.subMenus]
end
return x
else
return self.parent.subMenus[k-1]
end
end
end
else
return self
end
end
Test = Menu.newSubMenu()
Test:setup(Menu, "Test item")
Mahi = Menu.newSubMenu()
Mahi:setup(Menu, "Mahi item")
Mahi.open = true
Testx = Menu.newSubMenu()
Testx:setup(Mahi, "Lalall")
Testx.open= true
Sadmad = Menu.newSubMenu()
Sadmad:setup(Testx, "Woot")
Asd = Menu.newSubMenu()
Asd:setup(Menu, "Asd menu")
Asd.current = true
Menu.current = false
repeat
print(string.rep("\n",2))
Menu:print(0)
x=io.read()
if x == "z" then
x = Menu:getCurrentMenu()
print(Menu:getCurrentMenu().label)
print(Menu:getCurrentMenu():getNextMenu().label)
y = Menu:getCurrentMenu():getNextMenu()
x.current = false
y.current = true
elseif x == "a" then
x = Menu:getCurrentMenu()
y = Menu:getCurrentMenu():getPrevMenu()
x.current = false
y.current = true
end
until x == "sad"
"
there's the code, and when ever i try to move my current from "Asd menu" downwards, it'll error:
menu.lua:150: attempt to index a nil value
which doesn't make any sense, it's clearly declared, and I've tried adding prints and they always give me Asd menu O.o
Same goes for if I'll try to move from Woot to Asd menu, same exact error, and I have no idea why, since I added those prints
print(Menu:getCurrentMenu().label)
print(Menu:getCurrentMenu():getNextMenu().label)
and they do give me Asd menu, but then it says that trying to index a nil value at the second print line, but it sill does print? I'm out of ideas, any help out here?
You are missing a return statement in line 92.
Note that this line does not actually return anything, so the function is returning nil.
After changing it to return self.parent:getNextMenu(true) it seems to be working.
return (from s in db.StudentMarks
where s.Class == Class && s.Year == Year // this line
orderby s.Year, s.ExamType
select new StudentAddMarks()
{
--Obj
}).ToList();
I am going to return an Object depending on the Class and Year params. I want to remove the where condition when the Class and Year parames are null or zero.
Any ideas please.
Just add a clause handling null or zero values as well:
where ((Class != null && Class != 0) ? s.Class == Class : true) &&
((Year != null && Year != 0) ? s.Year == Year : true)
The above code uses the shorthand if-then-else syntax, that works as follows:
value = (condition ? if_true : if_false);
// ...is equivalent to...
if (condition)
{
value = if_true;
}
else
{
value = if_false;
}
This should work:
where (s.Class == Class && s.Year == Year) || Class == null ||
Class == 0 || Year == null || Year == 0